LLVM 20.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/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>

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 Expected< uint64_tgetNewShfFlags (SectionFlag AllFlags, uint16_t EMachine)
 
static uint64_t getSectionFlagsPreserveMask (uint64_t OldFlags, uint64_t NewFlags, uint16_t EMachine)
 
static void setSectionType (SectionBase &Sec, uint64_t Type)
 
static Error setSectionFlagsAndType (SectionBase &Sec, SectionFlag Flags, uint16_t EMachine)
 
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)
 
static Error dumpSectionToFile (StringRef SecName, StringRef Filename, Object &Obj)
 
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 verifyNoteSection (StringRef Name, endianness Endianness, ArrayRef< uint8_t > Data)
 
static Error handleArgs (const CommonConfig &Config, const ELFConfig &ELFConfig, ElfType OutputElfType, Object &Obj)
 
static Error writeOutput (const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
 

Typedef Documentation

◆ SectionPred

Definition at line 52 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 178 of file ELFObjcopy.cpp.

References Config, and createELFWriter().

Referenced by writeOutput().

◆ dumpSectionToFile()

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

◆ getNewShfFlags()

static Expected< uint64_t > getNewShfFlags ( SectionFlag  AllFlags,
uint16_t  EMachine 
)
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,
uint16_t  EMachine 
)
static

◆ handleArgs()

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

Definition at line 681 of file ELFObjcopy.cpp.

References llvm::objcopy::Add, llvm::objcopy::elf::Object::addNewSymbolTable(), llvm::objcopy::elf::Object::addSection(), addSymbol(), llvm::objcopy::ELFConfig::AllowBrokenLinks, llvm::big, Config, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::createStringError(), llvm::Data, dumpSectionToFile(), llvm::objcopy::elf::ELFT_ELF32LE, llvm::objcopy::elf::ELFT_ELF64LE, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::end(), llvm::objcopy::elf::Object::Entry, llvm::objcopy::ELFConfig::EntryExpr, llvm::ELF::ET_REL, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::find(), llvm::objcopy::elf::SectionBase::Flags, handleUserSection(), I, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::invalid_argument, llvm::little, llvm::objcopy::elf::Object::Machine, llvm::make_range(), Name, llvm::objcopy::elf::SectionBase::Name, llvm::objcopy::SectionRename::NewFlags, llvm::objcopy::SectionFlagsUpdate::NewFlags, llvm::objcopy::SectionRename::NewName, llvm::objcopy::ELFConfig::NewSymbolVisibility, llvm::objcopy::elf::Object::OSABI, llvm::objcopy::elf::Object::removeSections(), replaceAndRemoveSections(), llvm::objcopy::elf::Object::sections(), llvm::objcopy::elf::Object::segments(), llvm::objcopy::Set, setSectionFlagsAndType(), setSectionType(), llvm::ELF::SHF_ALLOC, llvm::ELF::SHT_NOBITS, llvm::ELF::SHT_NOTE, llvm::objcopy::Subtract, llvm::Error::success(), llvm::objcopy::elf::Object::SymbolTable, llvm::StringMap< ValueTy, AllocatorTy >::try_emplace(), llvm::objcopy::elf::SectionBase::Type, llvm::objcopy::elf::Object::Type, updateAndRemoveSymbols(), llvm::objcopy::elf::Object::updateSection(), llvm::Twine::utohexstr(), verifyNoteSection(), and llvm::objcopy::ELFConfig::VerifyNoteSections.

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

◆ 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

◆ onlyKeepDWOPred()

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

Definition at line 62 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

◆ setSectionFlagsAndType()

static Error setSectionFlagsAndType ( SectionBase Sec,
SectionFlag  Flags,
uint16_t  EMachine 
)
static

◆ setSectionType()

static void setSectionType ( SectionBase Sec,
uint64_t  Type 
)
static

◆ updateAndRemoveSymbols()

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

◆ verifyNoteSection()

static Error verifyNoteSection ( StringRef  Name,
endianness  Endianness,
ArrayRef< uint8_t >  Data 
)
static

◆ writeOutput()

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