aboutsummaryrefslogtreecommitdiff
path: root/lld/COFF/Writer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-03 14:10:23 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-07-03 14:10:23 +0000
commit145449b1e420787bb99721a429341fa6be3adfb6 (patch)
tree1d56ae694a6de602e348dd80165cf881a36600ed /lld/COFF/Writer.cpp
parentecbca9f5fb7d7613d2b94982c4825eb0d33d6842 (diff)
Diffstat (limited to 'lld/COFF/Writer.cpp')
-rw-r--r--lld/COFF/Writer.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 12db942f1db5..df60c9032b2d 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -332,7 +332,7 @@ void OutputSection::writeHeaderTo(uint8_t *buf) {
*hdr = header;
if (stringTableOff) {
// If name is too long, write offset into the string table as a name.
- sprintf(hdr->Name, "/%d", stringTableOff);
+ encodeSectionName(hdr->Name, stringTableOff);
} else {
assert(!config->debug || name.size() <= COFF::NameSize ||
(hdr->Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0);
@@ -712,7 +712,7 @@ bool Writer::fixGnuImportChunks() {
bool hasIdata = false;
// Sort all .idata$* chunks, grouping chunks from the same library,
- // with alphabetical ordering of the object fils within a library.
+ // with alphabetical ordering of the object files within a library.
for (auto it : partialSections) {
PartialSection *pSec = it.second;
if (!pSec->name.startswith(".idata"))
@@ -926,8 +926,14 @@ void Writer::createSections() {
// Move DISCARDABLE (or non-memory-mapped) sections to the end of file
// because the loader cannot handle holes. Stripping can remove other
// discardable ones than .reloc, which is first of them (created early).
- if (s->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE)
+ if (s->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) {
+ // Move discardable sections named .debug_ to the end, after other
+ // discardable sections. Stripping only removes the sections named
+ // .debug_* - thus try to avoid leaving holes after stripping.
+ if (s->name.startswith(".debug_"))
+ return 3;
return 2;
+ }
// .rsrc should come at the end of the non-discardable sections because its
// size may change by the Win32 UpdateResources() function, causing
// subsequent sections to move (see https://crbug.com/827082).