[PATCH] D59986: [ELF] Respect NonAlloc when copying flags from the previous sections
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 29 03:47:27 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: ruiu, grimar.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
If the output section contains only symbol assignments, we copy flags
from the previous sections. Don't set SHF_ALLOC if NonAlloc is true.
We also have to change the type from SHT_NOBITS to SHT_PROGBITS.
In BFD, bfd_elf_get_default_section_type maps non-alloctable sections to SHT_PROGBITS.
Fixes PR38626
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D59986
Files:
ELF/LinkerScript.cpp
ELF/ScriptParser.cpp
test/ELF/linkerscript/info-section-type.s
Index: test/ELF/linkerscript/info-section-type.s
===================================================================
--- test/ELF/linkerscript/info-section-type.s
+++ test/ELF/linkerscript/info-section-type.s
@@ -29,6 +29,10 @@
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+# RUN: echo "SECTIONS { .bar (INFO) : { . += 1; } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+
# RUN: echo "SECTIONS { .bar 0x20000 (INFO) : { *(.foo) } };" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -752,6 +752,7 @@
} else {
skip(); // This is "COPY", "INFO" or "OVERLAY".
Cmd->NonAlloc = true;
+ Cmd->Type = SHT_PROGBITS;
}
expect(")");
return true;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -886,7 +886,8 @@
// in case it is empty.
bool IsEmpty = getInputSections(Sec).empty();
if (IsEmpty)
- Sec->Flags = Flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR);
+ Sec->Flags =
+ Flags & ((Sec->NonAlloc ? 0 : SHF_ALLOC) | SHF_WRITE | SHF_EXECINSTR);
if (IsEmpty && isDiscardable(*Sec)) {
Sec->Live = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59986.192795.patch
Type: text/x-patch
Size: 1560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190329/eb9397a4/attachment.bin>
More information about the llvm-commits
mailing list