[lld] r292777 - [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 01:36:20 PST 2017


Author: grimar
Date: Mon Jan 23 03:36:19 2017
New Revision: 292777

URL: http://llvm.org/viewvc/llvm-project?rev=292777&view=rev
Log:
[ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.

It is used in linux kernel script:
http://lxr.free-electrons.com/source/arch/x86/kernel/vmlinux.lds.S#L140

Though CONSTRUCTORS is ignored for ELF.

Differential revision: https://reviews.llvm.org/D28951

Added:
    lld/trunk/test/ELF/linkerscript/constructor.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=292777&r1=292776&r2=292777&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Jan 23 03:36:19 2017
@@ -1439,6 +1439,10 @@ ScriptParser::readOutputSectionDescripti
     } else if (Tok == "ASSERT") {
       Cmd->Commands.emplace_back(new AssertCommand(readAssert()));
       expect(";");
+    } else if (Tok == "CONSTRUCTORS") {
+      // CONSTRUCTORS is a keyword to make the linker recognize C++ ctors/dtors
+      // by name. This is for very old file formats such as ECOFF/XCOFF.
+      // For ELF, we should ignore.
     } else if (Tok == "FILL") {
       Cmd->Filler = readFill();
     } else if (Tok == "SORT") {

Added: lld/trunk/test/ELF/linkerscript/constructor.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/constructor.s?rev=292777&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/constructor.s (added)
+++ lld/trunk/test/ELF/linkerscript/constructor.s Mon Jan 23 03:36:19 2017
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { foo : { *(.foo) CONSTRUCTORS } }" > %t.script
+
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+# CHECK:      Sections:
+# CHECK-NEXT: Idx Name          Size
+# CHECK-NEXT:   0               00000000
+# CHECK-NEXT:   1 foo           00000001
+
+.section foo, "a"
+.byte 0




More information about the llvm-commits mailing list