[lld] r277986 - [ELF] - Linkerscript: do not define _edata, _end, _etext if SECTIONS is used.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 8 01:42:49 PDT 2016
Author: grimar
Date: Mon Aug 8 03:42:48 2016
New Revision: 277986
URL: http://llvm.org/viewvc/llvm-project?rev=277986&view=rev
Log:
[ELF] - Linkerscript: do not define _edata,_end,_etext if SECTIONS is used.
I faced that when tried to link FreeBSD kernel.
It was "duplicate symbol: _edata in (internal) and (internal)" error.
_data was a shared symbol that came from hack.so. At first it was replaced with DefinedRegular by the code
disabled in this patch and later when script tried to define the same symbol - the error was shown.
In the same situation (as given in testcase) ld defines them as UND. gold defines as ABS with zero value.
Patch just disables any operations of creating these symbols if script do layout.
Differential revision: https://reviews.llvm.org/D23206
Added:
lld/trunk/test/ELF/linkerscript/linkerscript-edata-etext.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/end.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=277986&r1=277985&r2=277986&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 8 03:42:48 2016
@@ -578,6 +578,10 @@ template <class ELFT> void Writer<ELFT>:
if (!isOutputDynamic<ELFT>())
Symtab.addIgnored("__tls_get_addr");
+ // If linker script do layout we do not need to create any standart symbols.
+ if (ScriptConfig->HasContents)
+ return;
+
auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym1,
DefinedRegular<ELFT> *&Sym2) {
Sym1 = Symtab.addIgnored(S, STV_DEFAULT);
Modified: lld/trunk/test/ELF/end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/end.s?rev=277986&r1=277985&r2=277986&view=diff
==============================================================================
--- lld/trunk/test/ELF/end.s (original)
+++ lld/trunk/test/ELF/end.s Mon Aug 8 03:42:48 2016
@@ -23,52 +23,6 @@
// DEFAULT-NEXT: Value: 0x12008
// DEFAULT: ]
-// If there is no .bss section, "_end" should point to the end of the .data section.
-// RUN: echo "SECTIONS { \
-// RUN: /DISCARD/ : { *(.bss) } }" > %t.script
-// RUN: ld.lld %t.o --script %t.script -o %t
-// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=NOBSS
-
-// NOBSS: Sections [
-// NOBSS: Name: .data
-// NOBSS-NEXT: Type:
-// NOBSS-NEXT: Flags [
-// NOBSS-NEXT: SHF_ALLOC
-// NOBSS-NEXT: SHF_WRITE
-// NOBSS-NEXT: ]
-// NOBSS-NEXT: Address: 0x159
-// NOBSS-NEXT: Offset:
-// NOBSS-NEXT: Size: 2
-// NOBSS: ]
-// NOBSS: Symbols [
-// NOBSS: Name: _end
-// NOBSS-NEXT: Value: 0x15B
-// NOBSS: ]
-
-// If the layout of the sections is changed, "_end" should point to the end of allocated address space.
-// RUN: echo "SECTIONS { \
-// RUN: .bss : { *(.bss) } \
-// RUN: .data : { *(.data) } \
-// RUN: .text : { *(.text) } }" > %t.script
-// RUN: ld.lld %t.o --script %t.script -o %t
-// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=TEXTATEND
-
-// TEXTATEND: Sections [
-// TEXTATEND: Name: .text
-// TEXTATEND-NEXT: Type:
-// TEXTATEND-NEXT: Flags [
-// TEXTATEND-NEXT: SHF_ALLOC
-// TEXTATEND-NEXT: SHF_EXECINSTR
-// TEXTATEND-NEXT: ]
-// TEXTATEND-NEXT: Address: 0x160
-// TEXTATEND-NEXT: Offset:
-// TEXTATEND-NEXT: Size: 1
-// TEXTATEND: ]
-// TEXTATEND: Symbols [
-// TEXTATEND: Name: _end
-// TEXTATEND-NEXT: Value: 0x161
-// TEXTATEND: ]
-
.global _start,_end
.text
_start:
Added: lld/trunk/test/ELF/linkerscript/linkerscript-edata-etext.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-edata-etext.s?rev=277986&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-edata-etext.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-edata-etext.s Mon Aug 8 03:42:48 2016
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { }" > %t.script
+# RUN: not ld.lld %t.o -script %t.script -o %t 2>&1 | FileCheck %s
+# CHECK: undefined symbol: _edata
+# CHECK: undefined symbol: _end
+# CHECK: undefined symbol: _etext
+
+.global _start,_end,_etext,_edata
+.text
+_start:
+ .quad _edata + 0x1
+ .quad _etext + 0x1
+ .quad _end + 0x1
+
+.data
+ .word 1
+.bss
+ .align 4
+ .space 6
More information about the llvm-commits
mailing list