[lld] r234163 - [LinkerScript] Handle symbols defined in linker scripts in case of shared lib

Simon Atanasyan simon at atanasyan.com
Mon Apr 6 08:15:01 PDT 2015


Author: atanasyan
Date: Mon Apr  6 10:15:01 2015
New Revision: 234163

URL: http://llvm.org/viewvc/llvm-project?rev=234163&view=rev
Log:
[LinkerScript] Handle symbols defined in linker scripts in case of shared lib

This patch is a follow-up to the rL232409 and allows define symbols
in a linker script in case of linking shared library.

Added:
    lld/trunk/test/elf/linkerscript/Inputs/simple-pic.o.yaml
    lld/trunk/test/elf/linkerscript/symbol-definition-so.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h

Modified: lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h?rev=234163&r1=234162&r2=234163&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h Mon Apr  6 10:15:01 2015
@@ -60,6 +60,7 @@ void DynamicLibraryWriter<ELFT>::buildDy
 }
 
 template <class ELFT> void DynamicLibraryWriter<ELFT>::addDefaultAtoms() {
+  OutputELFWriter<ELFT>::addDefaultAtoms();
   _runtimeFile->addAbsoluteAtom("_end");
 }
 
@@ -76,6 +77,7 @@ bool DynamicLibraryWriter<ELFT>::createI
 
 template <class ELFT>
 void DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() {
+  OutputELFWriter<ELFT>::finalizeDefaultAtomValues();
   lld::AtomLayout *underScoreEndAtom = this->_layout.findAbsoluteAtom("_end");
   assert(underScoreEndAtom);
 

Added: lld/trunk/test/elf/linkerscript/Inputs/simple-pic.o.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/Inputs/simple-pic.o.yaml?rev=234163&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/Inputs/simple-pic.o.yaml (added)
+++ lld/trunk/test/elf/linkerscript/Inputs/simple-pic.o.yaml Mon Apr  6 10:15:01 2015
@@ -0,0 +1,32 @@
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          16
+
+  - Name:          .data
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:  4
+    Size:          16
+
+Symbols:
+  Local:
+    - Name:        .data
+      Type:        STT_SECTION
+      Section:     .data
+    - Name:        .text
+      Type:        STT_SECTION
+      Section:     .text
+  Global:
+    - Name:        foo
+      Type:        STT_FUNC
+      Section:     .text
+      Size:        16

Added: lld/trunk/test/elf/linkerscript/symbol-definition-so.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/symbol-definition-so.test?rev=234163&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/symbol-definition-so.test (added)
+++ lld/trunk/test/elf/linkerscript/symbol-definition-so.test Mon Apr  6 10:15:01 2015
@@ -0,0 +1,32 @@
+/*
+We test whether we can define symbols in a linker script and have them exported
+to the output file symbol table. This test is the same as symbol-definition.test
+but make checking in case of shared library linking.
+
+We use the following linker script for this test:
+*/
+
+SECTIONS
+{
+  .text : { *(.text) }
+  MYSTRING = .;
+  .data : { *(.data) }
+}
+
+/*
+RUN: yaml2obj -format=elf %p/Inputs/simple-pic.o.yaml -o=%t.o
+
+RUN: lld -flavor gnu -target x86_64 -shared -T %s %t.o -o %t.so
+RUN: llvm-readobj -s -symbols %t.so | FileCheck -check-prefix CHECKSYMS %s
+
+CHECKSYMS:      Name: .data
+CHECKSYMS-NEXT: Type: SHT_PROGBITS
+CHECKSYMS-NEXT: Flags [
+CHECKSYMS-NEXT:   SHF_ALLOC
+CHECKSYMS-NEXT:   SHF_WRITE
+CHECKSYMS-NEXT: ]
+CHECKSYMS-NEXT: Address: 0x401060
+
+CHECKSYMS:      Name: MYSTRING
+CHECKSYMS-NEXT: Value: 0x401060
+*/





More information about the llvm-commits mailing list