LLVM  15.0.0git
Typedefs | Functions
ELFObjcopy.cpp File Reference
#include "llvm/ObjCopy/ELF/ELFObjcopy.h"
#include "ELFObject.h"
#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/ObjCopy/CommonConfig.h"
#include "llvm/ObjCopy/ELF/ELFConfig.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ELFTypes.h"
#include "llvm/Object/Error.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
Include dependency graph for ELFObjcopy.cpp:

Go to the source code of this file.

Typedefs

using SectionPred = std::function< bool(const SectionBase &Sec)>
 

Functions

static bool isDebugSection (const SectionBase &Sec)
 
static bool isDWOSection (const SectionBase &Sec)
 
static bool onlyKeepDWOPred (const Object &Obj, const SectionBase &Sec)
 
static uint64_t getNewShfFlags (SectionFlag AllFlags)
 
static uint64_t getSectionFlagsPreserveMask (uint64_t OldFlags, uint64_t NewFlags)
 
static void setSectionFlagsAndType (SectionBase &Sec, SectionFlag Flags)
 
static ElfType getOutputElfType (const Binary &Bin)
 
static ElfType getOutputElfType (const MachineInfo &MI)
 
static std::unique_ptr< WritercreateELFWriter (const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
 
static std::unique_ptr< WritercreateWriter (const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
 
template<class... Ts>
static Error makeStringError (std::error_code EC, const Twine &Msg, Ts &&...Args)
 
static Error dumpSectionToFile (StringRef SecName, StringRef Filename, Object &Obj)
 
static bool isCompressable (const SectionBase &Sec)
 
static Error replaceDebugSections (Object &Obj, function_ref< bool(const SectionBase &)> ShouldReplace, function_ref< Expected< SectionBase * >(const SectionBase *)> AddSection)
 
static bool isAArch64MappingSymbol (const Symbol &Sym)
 
static bool isArmMappingSymbol (const Symbol &Sym)
 
static bool isRequiredByABISymbol (const Object &Obj, const Symbol &Sym)
 
static bool isUnneededSymbol (const Symbol &Sym)
 
static Error updateAndRemoveSymbols (const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
 
static Error replaceAndRemoveSections (const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
 
static void addSymbol (Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
 
static Error handleUserSection (const NewSectionInfo &NewSection, function_ref< Error(StringRef, ArrayRef< uint8_t >)> F)
 
static Error handleArgs (const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
 
static Error writeOutput (const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
 

Typedef Documentation

◆ SectionPred

Definition at line 53 of file ELFObjcopy.cpp.

Function Documentation

◆ addSymbol()

static void addSymbol ( Object Obj,
const NewSymbolInfo SymInfo,
uint8_t  DefaultVisibility 
)
static

◆ createELFWriter()

static std::unique_ptr<Writer> createELFWriter ( const CommonConfig Config,
Object Obj,
raw_ostream Out,
ElfType  OutputElfType 
)
static

◆ createWriter()

static std::unique_ptr<Writer> createWriter ( const CommonConfig Config,
Object Obj,
raw_ostream Out,
ElfType  OutputElfType 
)
static

Definition at line 156 of file ELFObjcopy.cpp.

References createELFWriter(), and llvm::objcopy::CommonConfig::OutputFormat.

Referenced by writeOutput().

◆ dumpSectionToFile()

static Error dumpSectionToFile ( StringRef  SecName,
StringRef  Filename,
Object Obj 
)
static

◆ getNewShfFlags()

static uint64_t getNewShfFlags ( SectionFlag  AllFlags)
static

◆ getOutputElfType() [1/2]

static ElfType getOutputElfType ( const Binary Bin)
static

◆ getOutputElfType() [2/2]

static ElfType getOutputElfType ( const MachineInfo MI)
static

◆ getSectionFlagsPreserveMask()

static uint64_t getSectionFlagsPreserveMask ( uint64_t  OldFlags,
uint64_t  NewFlags 
)
static

◆ handleArgs()

static Error handleArgs ( const CommonConfig Config,
const ELFConfig ELFConfig,
Object Obj 
)
static

Definition at line 601 of file ELFObjcopy.cpp.

References llvm::objcopy::CommonConfig::AddGnuDebugLink, llvm::objcopy::elf::Object::addNewSymbolTable(), llvm::objcopy::CommonConfig::AddSection, llvm::objcopy::elf::Object::addSection(), addSymbol(), llvm::objcopy::CommonConfig::AllocSectionsPrefix, llvm::objcopy::ELFConfig::AllowBrokenLinks, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::count(), llvm::Data, llvm::objcopy::CommonConfig::DumpSection, dumpSectionToFile(), E, llvm::StringMapImpl::empty(), llvm::StringRef::empty(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::end(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::objcopy::elf::Object::Entry, llvm::objcopy::ELFConfig::EntryExpr, llvm::objcopy::CommonConfig::ExtractDWO, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::find(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::objcopy::elf::SectionBase::Flags, llvm::Optional< T >::getValue(), llvm::objcopy::CommonConfig::GnuDebugLinkCRC32, handleUserSection(), llvm::Optional< T >::hasValue(), I, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert(), llvm::objcopy::elf::Object::Machine, llvm::objcopy::elf::SectionBase::Name, llvm::objcopy::SectionRename::NewFlags, llvm::objcopy::SectionFlagsUpdate::NewFlags, llvm::objcopy::SectionRename::NewName, llvm::objcopy::ELFConfig::NewSymbolVisibility, llvm::objcopy::CommonConfig::OnlyKeepDebug, llvm::objcopy::elf::Object::OSABI, llvm::objcopy::CommonConfig::OutputArch, llvm::objcopy::elf::Object::removeSections(), replaceAndRemoveSections(), llvm::AMDGPU::ElfNote::SectionName, llvm::objcopy::elf::Object::sections(), llvm::objcopy::CommonConfig::SectionsToRename, llvm::objcopy::CommonConfig::SetSectionAlignment, llvm::objcopy::CommonConfig::SetSectionFlags, setSectionFlagsAndType(), llvm::ELF::SHF_ALLOC, llvm::ELF::SHT_NOBITS, llvm::ELF::SHT_NOTE, SI, llvm::objcopy::CommonConfig::SplitDWO, llvm::Error::success(), llvm::objcopy::CommonConfig::SymbolsToAdd, llvm::objcopy::elf::Object::SymbolTable, llvm::objcopy::elf::SectionBase::Type, updateAndRemoveSymbols(), llvm::objcopy::CommonConfig::UpdateSection, and llvm::objcopy::elf::Object::updateSection().

Referenced by llvm::objcopy::elf::executeObjcopyOnBinary(), llvm::objcopy::elf::executeObjcopyOnIHex(), and llvm::objcopy::elf::executeObjcopyOnRawBinary().

◆ handleUserSection()

static Error handleUserSection ( const NewSectionInfo NewSection,
function_ref< Error(StringRef, ArrayRef< uint8_t >)>  F 
)
static

◆ isAArch64MappingSymbol()

static bool isAArch64MappingSymbol ( const Symbol Sym)
static

◆ isArmMappingSymbol()

static bool isArmMappingSymbol ( const Symbol Sym)
static

◆ isCompressable()

static bool isCompressable ( const SectionBase Sec)
static

◆ isDebugSection()

static bool isDebugSection ( const SectionBase Sec)
static

◆ isDWOSection()

static bool isDWOSection ( const SectionBase Sec)
static

◆ isRequiredByABISymbol()

static bool isRequiredByABISymbol ( const Object Obj,
const Symbol Sym 
)
static

◆ isUnneededSymbol()

static bool isUnneededSymbol ( const Symbol Sym)
static

◆ makeStringError()

template<class... Ts>
static Error makeStringError ( std::error_code  EC,
const Twine Msg,
Ts &&...  Args 
)
static

◆ onlyKeepDWOPred()

static bool onlyKeepDWOPred ( const Object Obj,
const SectionBase Sec 
)
static

Definition at line 64 of file ELFObjcopy.cpp.

References isDWOSection(), and llvm::objcopy::elf::Object::SectionNames.

Referenced by replaceAndRemoveSections().

◆ replaceAndRemoveSections()

static Error replaceAndRemoveSections ( const CommonConfig Config,
const ELFConfig ELFConfig,
Object Obj 
)
static

◆ replaceDebugSections()

static Error replaceDebugSections ( Object Obj,
function_ref< bool(const SectionBase &)>  ShouldReplace,
function_ref< Expected< SectionBase * >(const SectionBase *)>  AddSection 
)
static

◆ setSectionFlagsAndType()

static void setSectionFlagsAndType ( SectionBase Sec,
SectionFlag  Flags 
)
static

◆ updateAndRemoveSymbols()

static Error updateAndRemoveSymbols ( const CommonConfig Config,
const ELFConfig ELFConfig,
Object Obj 
)
static

Definition at line 270 of file ELFObjcopy.cpp.

References llvm::objcopy::elf::Symbol::Binding, llvm::objcopy::CommonConfig::DiscardMode, llvm::StringRef::empty(), llvm::objcopy::NameMatcher::empty(), llvm::objcopy::elf::Symbol::getShndx(), I, if(), llvm::objcopy::elf::Symbol::isCommon(), llvm::objcopy::elf::Object::isRelocatable(), isRequiredByABISymbol(), isUnneededSymbol(), llvm::objcopy::ELFConfig::KeepFileSymbols, llvm::objcopy::ELFConfig::LocalizeHidden, llvm::objcopy::NameMatcher::matches(), llvm::objcopy::elf::Symbol::Name, llvm::objcopy::CommonConfig::OnlySection, llvm::objcopy::elf::Symbol::Referenced, llvm::objcopy::elf::Object::removeSymbols(), llvm::objcopy::elf::Object::sections(), llvm::ELF::SHN_UNDEF, llvm::StringRef::startswith(), llvm::ELF::STB_GLOBAL, llvm::ELF::STB_LOCAL, llvm::ELF::STB_WEAK, llvm::objcopy::CommonConfig::StripAll, llvm::objcopy::CommonConfig::StripAllGNU, llvm::objcopy::CommonConfig::StripDebug, llvm::objcopy::CommonConfig::StripUnneeded, llvm::ELF::STT_FILE, llvm::ELF::STT_SECTION, llvm::ELF::STV_HIDDEN, llvm::ELF::STV_INTERNAL, llvm::Error::success(), llvm::objcopy::CommonConfig::SymbolsPrefix, llvm::objcopy::CommonConfig::SymbolsToGlobalize, llvm::objcopy::CommonConfig::SymbolsToKeep, llvm::objcopy::CommonConfig::SymbolsToKeepGlobal, llvm::objcopy::CommonConfig::SymbolsToLocalize, llvm::objcopy::CommonConfig::SymbolsToRemove, llvm::objcopy::CommonConfig::SymbolsToRename, llvm::objcopy::CommonConfig::SymbolsToWeaken, llvm::objcopy::elf::Object::SymbolTable, llvm::objcopy::elf::Symbol::Type, llvm::objcopy::CommonConfig::UnneededSymbolsToRemove, llvm::objcopy::elf::SymbolTableSection::updateSymbols(), llvm::objcopy::elf::Symbol::Visibility, and llvm::objcopy::CommonConfig::Weaken.

Referenced by handleArgs().

◆ writeOutput()

static Error writeOutput ( const CommonConfig Config,
Object Obj,
raw_ostream Out,
ElfType  OutputElfType 
)
static