[lld] r258672 - [ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 00:44:50 PST 2016


Author: grimar
Date: Mon Jan 25 02:44:38 2016
New Revision: 258672

URL: http://llvm.org/viewvc/llvm-project?rev=258672&view=rev
Log:
[ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.

Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

Differential revision: http://reviews.llvm.org/D16405

Added:
    lld/trunk/test/ELF/Inputs/symbol-override.s
    lld/trunk/test/ELF/symbol-override.s
Modified:
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/test/ELF/mips-dynamic.s

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=258672&r1=258671&r2=258672&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Jan 25 02:44:38 2016
@@ -53,6 +53,13 @@ template <class ELFT> int SymbolBody::co
   if (IsUsedInRegularObj || Other->IsUsedInRegularObj)
     IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
 
+  // We want to export all symbols that exist both in the executable
+  // and in DSOs, so that the symbols in the executable can interrupt
+  // symbols in the DSO at runtime.
+  if (isShared() != Other->isShared())
+    if (isa<DefinedRegular<ELFT>>(isShared() ? Other : this))
+      IsUsedInDynamicReloc = Other->IsUsedInDynamicReloc = true;
+
   if (L != R)
     return -1;
   if (!std::get<0>(L) || !std::get<1>(L) || !std::get<2>(L))

Added: lld/trunk/test/ELF/Inputs/symbol-override.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/symbol-override.s?rev=258672&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/symbol-override.s (added)
+++ lld/trunk/test/ELF/Inputs/symbol-override.s Mon Jan 25 02:44:38 2016
@@ -0,0 +1,16 @@
+.text
+.globl foo
+.type foo, at function
+foo:
+nop
+
+.globl bar
+.type bar, at function
+bar:
+nop
+
+.globl do
+.type do, at function
+do: 
+callq foo at PLT
+callq bar at PLT

Modified: lld/trunk/test/ELF/mips-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-dynamic.s?rev=258672&r1=258671&r2=258672&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-dynamic.s (original)
+++ lld/trunk/test/ELF/mips-dynamic.s Mon Jan 25 02:44:38 2016
@@ -47,8 +47,8 @@
 # EXE-DAG:    0x70000005 MIPS_FLAGS           NOTPOT
 # EXE-DAG:    0x70000006 MIPS_BASE_ADDRESS
 # EXE-DAG:    0x7000000A MIPS_LOCAL_GOTNO     2
-# EXE-DAG:    0x70000011 MIPS_SYMTABNO        1
-# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x1
+# EXE-DAG:    0x70000011 MIPS_SYMTABNO        2
+# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x2
 # EXE-DAG:    0x70000016 MIPS_RLD_MAP         [[RLDMAPADDR]]
 # EXE:      ]
 

Added: lld/trunk/test/ELF/symbol-override.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-override.s?rev=258672&view=auto
==============================================================================
--- lld/trunk/test/ELF/symbol-override.s (added)
+++ lld/trunk/test/ELF/symbol-override.s Mon Jan 25 02:44:38 2016
@@ -0,0 +1,46 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/symbol-override.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t2.so
+// RUN: ld.lld %t1.o %t2.so -o %t
+// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
+
+// CHECK:      DynamicSymbols [
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name:
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined
+// CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: do
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Global
+// CHECK-NEXT:     Type: Function
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined
+// CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: foo
+// CHECK-NEXT:     Value: 0x11000
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Global
+// CHECK-NEXT:     Type: Function
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: .text
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+
+.text
+.globl foo
+.type foo, at function
+foo:  
+nop
+
+.text
+.globl _start
+_start:
+callq do




More information about the llvm-commits mailing list