28using namespace object;
49 auto LinkTarget = std::move(*LinkTargetOrErr);
54 std::vector<uint8_t>
Data(CRCPos + 4);
69 Sec.Header.VirtualSize = NeedVA ? Sec.getContents().size() : 0u;
70 Sec.Header.VirtualAddress = NeedVA ?
getNextRVA(Obj) : 0u;
71 Sec.Header.SizeOfRawData =
72 NeedVA ?
alignTo(Sec.Header.VirtualSize,
74 : Sec.getContents().size();
76 Sec.Header.PointerToRelocations = 0;
77 Sec.Header.PointerToLinenumbers = 0;
79 Sec.Header.NumberOfLinenumbers = 0;
120 NewCharacteristics |=
131 return NewCharacteristics;
141 std::unique_ptr<FileOutputBuffer> Buffer;
143 Buffer = std::move(*
B);
145 return B.takeError();
147 llvm::copy(Contents, Buffer->getBufferStart());
148 if (
Error E = Buffer->commit())
174 if (isDebugSection(Sec) &&
175 (Sec.Header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) != 0)
185 if (
Config.OnlyKeepDebug) {
202 !
Config.SymbolsToRemove.empty())
208 if (
I !=
Config.SymbolsToRename.end())
223 "'" +
Config.OutputFilename +
"': not stripping symbol '" +
224 Sym.
Name.
str() +
"' because it is named in a relocation");
235 if (
Config.StripUnneeded ||
255 if (!
Config.SetSectionFlags.empty())
257 const auto It =
Config.SetSectionFlags.find(Sec.
Name);
258 if (It !=
Config.SetSectionFlags.end())
266 if (It !=
Config.SetSectionFlags.end())
272 ArrayRef(
reinterpret_cast<const uint8_t *
>(
280 return Sec.Name == NewSection.SectionName;
284 "could not find section with name '%s'",
286 size_t ContentSize = It->getContents().size();
290 "section '%s' cannot be updated because it does not have contents",
292 if (ContentSize < NewSection.SectionData->getBufferSize())
295 "new section cannot be larger than previous section");
296 It->setOwnedContents({NewSection.
SectionData->getBufferStart(),
300 if (!
Config.AddGnuDebugLink.empty())
309 "'" +
Config.OutputFilename +
310 "': unable to set subsystem on a relocatable object file");
330 assert(Obj &&
"Unable to deserialize COFF object");
334 if (
Error E = Writer.write())
ReachingDefAnalysis InstSet & ToRemove
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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),...
size_t size() const
size - Get the array size.
This class represents an Operation in the Expression.
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 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...
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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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 Error dumpSection(Object &O, StringRef SectionName, StringRef FileName)
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.
OutputIt copy(R &&Range, OutputIt Out)
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
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
ArrayRef< uint8_t > getContents() const
object::coff_symbol32 Sym
support::ulittle32_t Characteristics
SectionNumberType SectionNumber