[PATCH] D36468: [ELF] - Allow discard COMMON from linkerscript.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 07:39:11 PDT 2017
grimar created this revision.
Herald added a subscriber: emaste.
This patch allows following construction:
`/DISCARD/ : { *(COMMON) }`
Previously LLD would crash.
Behavior is consistent with ld.bfd.
ld.gold looks ignores such scripts.
https://reviews.llvm.org/D36468
Files:
ELF/Writer.cpp
test/ELF/linkerscript/discard-common.s
Index: test/ELF/linkerscript/discard-common.s
===================================================================
--- test/ELF/linkerscript/discard-common.s
+++ test/ELF/linkerscript/discard-common.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple x86_64-pc-linux %s -o %t.o -filetype=obj
+# RUN: echo "SECTIONS { /DISCARD/ : { *(COMMON) } }" > %t.script
+# RUN: ld.lld -o %t -T %t.script %t.o
+# RUN: llvm-readobj -symbols -sections %t | FileCheck %s
+# CHECK-NOT: .bss
+# CHECK-NOT: foo
+
+.comm foo,4,4
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -451,6 +451,8 @@
if (auto *S = dyn_cast<MergeInputSection>(Sec))
if (!S->getSectionPiece(D->Value)->Live)
return false;
+ } else if (auto *D = dyn_cast<DefinedCommon>(&B)) {
+ return !Config->DefineCommon || (InX::Common && InX::Common->Live);
}
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36468.110197.patch
Type: text/x-patch
Size: 942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170808/16761d8b/attachment.bin>
More information about the llvm-commits
mailing list