27using namespace object;
48 auto LinkTarget = std::move(*LinkTargetOrErr);
53 std::vector<uint8_t>
Data(CRCPos + 4);
68 Sec.Header.VirtualSize = NeedVA ? Sec.getContents().size() : 0u;
69 Sec.Header.VirtualAddress = NeedVA ?
getNextRVA(Obj) : 0u;
70 Sec.Header.SizeOfRawData =
71 NeedVA ?
alignTo(Sec.Header.VirtualSize,
73 : Sec.getContents().size();
75 Sec.Header.PointerToRelocations = 0;
76 Sec.Header.PointerToLinenumbers = 0;
78 Sec.Header.NumberOfLinenumbers = 0;
119 NewCharacteristics |=
130 return NewCharacteristics;
144 if (isDebugSection(Sec) &&
145 (Sec.Header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) != 0)
179 Sym.Name =
I->getValue();
194 Sym.Name.
str() +
"' because it is named in a relocation");
198 if (!Sym.Referenced) {
204 Sym.Sym.SectionNumber == 0)
214 Sym.Sym.SectionNumber != 0)
242 ArrayRef(
reinterpret_cast<const uint8_t *
>(
250 return Sec.Name == NewSection.SectionName;
254 "could not find section with name '%s'",
256 size_t ContentSize = It->getContents().size();
260 "section '%s' cannot be updated because it does not have contents",
262 if (ContentSize < NewSection.SectionData->getBufferSize())
265 "new section cannot be larger than previous section");
266 It->setOwnedContents({NewSection.
SectionData->getBufferStart(),
280 "': unable to set subsystem on a relocatable object file");
300 assert(Obj &&
"Unable to deserialize COFF object");
304 if (
Error E = Writer.write())
ReachingDefAnalysis InstSet & ToRemove
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
bool startswith(StringRef Prefix) const
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool matches(StringRef S) const
Expected< std::unique_ptr< Object > > create() const
This class implements an extremely fast bulk output stream that can only output to a stream.
@ IMAGE_SCN_ALIGN_64BYTES
@ IMAGE_SCN_ALIGN_128BYTES
@ IMAGE_SCN_ALIGN_256BYTES
@ IMAGE_SCN_ALIGN_1024BYTES
@ IMAGE_SCN_ALIGN_512BYTES
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_ALIGN_4096BYTES
@ IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_ALIGN_8192BYTES
@ IMAGE_SCN_ALIGN_16BYTES
@ IMAGE_SCN_ALIGN_32BYTES
@ IMAGE_SCN_ALIGN_2048BYTES
@ IMAGE_SYM_CLASS_STATIC
Static.
static bool isDebugSection(const Section &Sec)
Error executeObjcopyOnBinary(const CommonConfig &Config, const COFFConfig &, object::COFFObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and COFFConfig to In and writes the result into Out.
static void addSection(Object &Obj, StringRef Name, ArrayRef< uint8_t > Contents, uint32_t Characteristics)
static uint32_t flagsToCharacteristics(SectionFlag AllFlags, uint32_t OldChar)
static uint64_t getNextRVA(const Object &Obj)
static Error handleArgs(const CommonConfig &Config, const COFFConfig &COFFConfig, Object &Obj)
static Error addGnuDebugLink(Object &Obj, StringRef DebugLinkFile)
static Expected< std::vector< uint8_t > > createGnuDebugLinkSectionContents(StringRef File)
void write32le(void *P, uint32_t V)
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
uint32_t crc32(ArrayRef< uint8_t > Data)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
std::optional< unsigned > MinorSubsystemVersion
std::optional< unsigned > Subsystem
std::optional< unsigned > MajorSubsystemVersion
NameMatcher SymbolsToRemove
std::vector< NewSectionInfo > UpdateSection
StringRef AddGnuDebugLink
StringMap< SectionFlagsUpdate > SetSectionFlags
NameMatcher UnneededSymbolsToRemove
std::vector< NewSectionInfo > AddSection
StringMap< StringRef > SymbolsToRename
std::shared_ptr< MemoryBuffer > SectionData
iterator_range< std::vector< Symbol >::iterator > getMutableSymbols()
void truncateSections(function_ref< bool(const Section &)> ToTruncate)
void addSections(ArrayRef< Section > NewSections)
object::pe32plus_header PeHeader
void removeSections(function_ref< bool(const Section &)> ToRemove)
iterator_range< std::vector< Section >::iterator > getMutableSections()
ArrayRef< Section > getSections() const
Error removeSymbols(function_ref< Expected< bool >(const Symbol &)> ToRemove)
void setOwnedContents(std::vector< uint8_t > &&Data)
object::coff_section Header
std::vector< Relocation > Relocs
support::ulittle32_t Characteristics