[lld] r276965 - [ELF] - Linkerscript: ignore SORT(CONSTRUCTORS)
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 00:18:24 PDT 2016
Author: grimar
Date: Thu Jul 28 02:18:23 2016
New Revision: 276965
URL: http://llvm.org/viewvc/llvm-project?rev=276965&view=rev
Log:
[ELF] - Linkerscript: ignore SORT(CONSTRUCTORS)
Some scripts can contain SORT(CONSTRUCTORS) expression:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l152
for ELF it just a nop:
"When linking object file formats which do not support arbitrary sections, such as ECOFF and XCOFF, the linker will automatically recognize C++ global constructors and destructors by name. For these object file formats, the CONSTRUCTORS command tells the linker to place constructor information in the output section where the CONSTRUCTORS command appears. The CONSTRUCTORS command is ignored for other object file formats."
(http://www.sourceware.org/binutils/docs-2.10/ld_3.html)
So patch implements ignoring.
Differential revision: https://reviews.llvm.org/D22848
Added:
lld/trunk/test/ELF/linkerscript/linkerscript-sort-constructors.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276965&r1=276964&r2=276965&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Jul 28 02:18:23 2016
@@ -442,6 +442,7 @@ private:
unsigned readPhdrType();
void readProvide(bool Hidden);
void readAlign(OutputSectionCommand *Cmd);
+ void readSort();
Expr readExpr();
Expr readExpr1(Expr Lhs, int MinPrec);
@@ -701,6 +702,12 @@ void ScriptParser::readAlign(OutputSecti
expect(")");
}
+void ScriptParser::readSort() {
+ expect("(");
+ expect("CONSTRUCTORS");
+ expect(")");
+}
+
void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec);
Opt.Commands.emplace_back(Cmd);
@@ -736,6 +743,8 @@ void ScriptParser::readOutputSectionDesc
readProvide(false);
} else if (Tok == "PROVIDE_HIDDEN") {
readProvide(true);
+ } else if (Tok == "SORT") {
+ readSort();
} else {
setError("unknown command " + Tok);
}
Added: lld/trunk/test/ELF/linkerscript/linkerscript-sort-constructors.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-sort-constructors.s?rev=276965&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-sort-constructors.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-sort-constructors.s Thu Jul 28 02:18:23 2016
@@ -0,0 +1,5 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: echo "SECTIONS { .aaa : { SORT(CONSTRUCTORS) } }" > %t1.script
+# RUN: ld.lld -shared -o %t1 --script %t1.script %t1.o
+# RUN: llvm-readobj %t1 > /dev/null
More information about the llvm-commits
mailing list