Go to the documentation of this file.
44 #include <system_error>
98 return (OldFlags & PreserveMask) | (NewFlags & ~PreserveMask);
138 switch (OutputElfType) {
140 return std::make_unique<ELFWriter<ELF32LE>>(Obj, Out, !Config.
StripSections,
143 return std::make_unique<ELFWriter<ELF64LE>>(Obj, Out, !Config.
StripSections,
146 return std::make_unique<ELFWriter<ELF32BE>>(Obj, Out, !Config.
StripSections,
149 return std::make_unique<ELFWriter<ELF64BE>>(Obj, Out, !Config.
StripSections,
159 case FileFormat::Binary:
160 return std::make_unique<BinaryWriter>(Obj, Out);
161 case FileFormat::IHex:
162 return std::make_unique<IHexWriter>(Obj, Out);
168 template <
class... Ts>
171 std::string FullMsg = (EC.message() +
": " +
Msg).str();
178 if (Sec.Name == SecName) {
181 "cannot dump section '%s': it has no contents",
182 SecName.
str().c_str());
187 std::unique_ptr<FileOutputBuffer> Buf =
std::move(*BufferOrErr);
188 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(),
189 Buf->getBufferStart());
190 if (
Error E = Buf->commit())
196 SecName.
str().c_str());
212 if (ShouldReplace(Sec))
213 ToReplace.push_back(&Sec);
222 FromTo[
S] = *NewSection;
233 if (!
Name.consume_front(
"$x") && !
Name.consume_front(
"$d"))
235 return Name.empty() ||
Name.startswith(
".");
243 if (!
Name.consume_front(
"$a") && !
Name.consume_front(
"$d") &&
244 !
Name.consume_front(
"$t"))
246 return Name.empty() ||
Name.startswith(
".");
314 Sym.
Name = std::string(
I->getValue());
329 auto RemoveSymbolsPred = [&](
const Symbol &Sym) {
381 RemovePred = [RemovePred](
const SectionBase &Sec) {
386 RemovePred = [RemovePred, &Obj](
const SectionBase &Sec) {
391 RemovePred = [RemovePred, &Obj](
const SectionBase &Sec) {
409 RemovePred = [RemovePred](
const SectionBase &Sec) {
410 return RemovePred(Sec) || Sec.ParentSegment ==
nullptr;
415 RemovePred = [RemovePred](
const SectionBase &Sec) {
421 RemovePred = [RemovePred, &Obj](
const SectionBase &Sec) {
426 return (Sec.Flags &
SHF_ALLOC) == 0 && Sec.ParentSegment ==
nullptr;
430 RemovePred = [RemovePred, &Obj](
const SectionBase &Sec) {
443 if (Sec.ParentSegment !=
nullptr)
449 RemovePred = [RemovePred](
const SectionBase &Sec) {
454 return (Sec.Flags &
SHF_ALLOC) != 0 && !Sec.ParentSegment;
460 RemovePred = [&Config, RemovePred, &Obj](
const SectionBase &Sec) {
482 RemovePred = [&Config, RemovePred](
const SectionBase &Sec) {
487 return RemovePred(Sec);
498 RemovePred = [&Obj, RemovePred](
const SectionBase &Sec) {
501 return RemovePred(Sec);
519 [](
const SectionBase &
S) {
return isa<CompressedSection>(&
S); },
532 uint8_t DefaultVisibility) {
538 uint8_t Visibility = DefaultVisibility;
542 case SymbolFlag::Global:
545 case SymbolFlag::Local:
548 case SymbolFlag::Weak:
557 case SymbolFlag::Protected:
566 case SymbolFlag::Object:
569 case SymbolFlag::Function:
572 case SymbolFlag::IndirectFunction:
610 [&Obj](
const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); });
633 std::vector<RelocationSectionBase *> RelocSections;
636 auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec);
640 Sec.Name = std::string(SR.
NewName);
643 RenamedSections.
insert(&Sec);
644 }
else if (RelocSec && !(Sec.Flags &
SHF_ALLOC))
651 RelocSections.push_back(RelocSec);
656 auto Iter = RenamedSections.
find(RelocSec->getSection());
657 if (Iter != RenamedSections.
end())
658 RelocSec->Name = (RelocSec->getNamePrefix() + (*Iter)->Name).str();
670 PrefixedSections.
insert(&Sec);
671 }
else if (
auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec)) {
679 const SectionBase *TargetSec = RelocSec->getSection();
685 if (PrefixedSections.
count(TargetSec))
686 Sec.
Name = (RelocSec->getNamePrefix() + TargetSec->
Name).str();
700 Sec.Align =
I->second;
713 if (
Name.startswith(
".note") &&
Name !=
".note.GNU-stack")
760 std::unique_ptr<Writer>
Writer =
779 return writeOutput(Config, **Obj, Out, OutputElfType);
797 return writeOutput(Config, **Obj, Out, OutputElfType);
virtual Expected< std::unique_ptr< Object > > create(bool EnsureSymtab) const =0
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
This is an optimization pass for GlobalISel generic memory operations.
uint16_t getShndx() const
Error updateSection(StringRef Name, ArrayRef< uint8_t > Data)
static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
NameMatcher SymbolsToWeaken
std::function< bool(const SectionBase &Sec)> SectionPred
bool matches(StringRef S) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator find(const_arg_type_t< ValueT > V)
Optional< MachineInfo > OutputArch
static bool isCompressable(const SectionBase &Sec)
static ErrorSuccess success()
Create a success value.
static Error handleUserSection(const NewSectionInfo &NewSection, function_ref< Error(StringRef, ArrayRef< uint8_t >)> F)
bool isRelocatable() const
Error removeSymbols(function_ref< bool(const Symbol &)> ToRemove)
StringMap< StringRef > SymbolsToRename
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_NODISCARD bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Tagged union holding either a T or a Error.
iterator find(StringRef Key)
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Error replaceSections(const DenseMap< SectionBase *, SectionBase * > &FromTo)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
T & addSection(Ts &&...Args)
SectionBase * findSection(StringRef Name)
Error addNewSymbolTable()
void addSymbol(Twine Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn, uint64_t Value, uint8_t Visibility, uint16_t Shndx, uint64_t SymbolSize)
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DebugCompressionType CompressionType
NameMatcher SymbolsToKeep
StringTableSection * SectionNames
std::vector< NewSectionInfo > AddSection
static Error writeOutput(const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
std::vector< StringRef > DumpSection
static void setSectionFlagsAndType(SectionBase &Sec, SectionFlag Flags)
Error executeObjcopyOnBinary(const CommonConfig &Config, const ELFConfig &ELFConfig, object::ELFObjectFileBase &In, raw_ostream &Out)
Apply the transformations described by Config and ELFConfig to In and writes the result into Out.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
NameMatcher SymbolsToGlobalize
This class implements an extremely fast bulk output stream that can only output to a stream.
const SectionBase * getStrTab() const
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
static bool isArmMappingSymbol(const Symbol &Sym)
std::shared_ptr< MemoryBuffer > SectionData
static Error replaceDebugSections(Object &Obj, function_ref< bool(const SectionBase &)> ShouldReplace, function_ref< Expected< SectionBase * >(const SectionBase *)> AddSection)
An efficient, type-erasing, non-owning reference to a callable.
Implements a dense probed hash-table based set.
NameMatcher SymbolsToLocalize
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
NameMatcher SymbolsToKeepGlobal
NameMatcher UnneededSymbolsToRemove
static std::unique_ptr< Writer > createWriter(const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
static Error updateAndRemoveSymbols(const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
static bool isRequiredByABISymbol(const Object &Obj, const Symbol &Sym)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
static std::unique_ptr< Writer > createELFWriter(const CommonConfig &Config, Object &Obj, raw_ostream &Out, ElfType OutputElfType)
static bool isAArch64MappingSymbol(const Symbol &Sym)
static bool onlyKeepDWOPred(const Object &Obj, const SectionBase &Sec)
static ElfType getOutputElfType(const Binary &Bin)
Optional< SectionFlag > NewFlags
constexpr const T & getValue() const &
StandardInstrumentations SI(Debug, VerifyEach)
uint32_t GnuDebugLinkCRC32
static Error makeStringError(std::error_code EC, const Twine &Msg, Ts &&...Args)
print Print MemDeps of function
std::vector< NewSymbolInfo > SymbolsToAdd
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
if(llvm_vc STREQUAL "") set(fake_version_inc "$
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
static Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
uint8_t NewSymbolVisibility
StringMap< uint64_t > SetSectionAlignment
const CustomOperand< const MCSubtargetInfo & > Msg[]
void updateSymbols(function_ref< void(Symbol &)> Callable)
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SectionTableRef sections() const
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static uint64_t getSectionFlagsPreserveMask(uint64_t OldFlags, uint64_t NewFlags)
Error removeSections(bool AllowBrokenLinks, std::function< bool(const SectionBase &)> ToRemove)
Lightweight error class with error context and mandatory checking.
std::vector< NewSectionInfo > UpdateSection
virtual Error finalize()=0
Error executeObjcopyOnRawBinary(const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In, raw_ostream &Out)
Apply the transformations described by Config and ELFConfig to In, which is treated as a raw binary i...
static bool isDebugSection(const SectionBase &Sec)
Optional< StringRef > ExtractPartition
static bool isDWOSection(const SectionBase &Sec)
Error takeError()
Take ownership of the stored error.
StringMap< SectionRename > SectionsToRename
static uint64_t getNewShfFlags(SectionFlag AllFlags)
static bool isUnneededSymbol(const Symbol &Sym)
static Error replaceAndRemoveSections(const CommonConfig &Config, const ELFConfig &ELFConfig, Object &Obj)
NameMatcher SymbolsToRemove
bool DecompressDebugSections
bool ExtractMainPartition
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
static Error dumpSectionToFile(StringRef SecName, StringRef Filename, Object &Obj)
std::function< uint64_t(uint64_t)> EntryExpr
SymbolTableSection * SymbolTable
StringMap< SectionFlagsUpdate > SetSectionFlags
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same we currently get code like const It could be done with a smaller encoding like local tee $pop5 local copy
LLVM Value Representation.
StringRef AddGnuDebugLink
Instrumentation for Order File
StringRef AllocSectionsPrefix
Error executeObjcopyOnIHex(const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In, raw_ostream &Out)
Apply the transformations described by Config and ELFConfig to In, which must represent an IHex file,...