[PATCH] D26496: [ELF] - Allow calls to a protected function in a shared library from non-PIC code.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 04:40:05 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

GNU linkers allow to do that,
this should fix the https://llvm.org/bugs/show_bug.cgi?id=30960.


https://reviews.llvm.org/D26496

Files:
  ELF/Relocations.cpp
  test/ELF/Inputs/protected-shared-func.s
  test/ELF/protected-shared-func.s


Index: test/ELF/protected-shared-func.s
===================================================================
--- test/ELF/protected-shared-func.s
+++ test/ELF/protected-shared-func.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/protected-shared-func.s -o %t2.o
+# RUN: ld.lld -shared %t2.o -o %t2.so
+# RUN: ld.lld %t.o %t2.so -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=xxx
+
+.globl _start
+_start:
+ callq bar
Index: test/ELF/Inputs/protected-shared-func.s
===================================================================
--- test/ELF/Inputs/protected-shared-func.s
+++ test/ELF/Inputs/protected-shared-func.s
@@ -0,0 +1,5 @@
+.text
+.protected bar
+.globl bar
+.type bar, at function
+bar:
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -445,7 +445,10 @@
           (Name.empty() ? "readonly segment" : "symbol " + Name));
     return Expr;
   }
-  if (Body.getVisibility() != STV_DEFAULT) {
+
+  // GNU linkers allows non PIC program calls to a protected
+  // function in a shared library. We do the same.
+  if (!Body.isFunc() && Body.getVisibility() != STV_DEFAULT) {
     error("cannot preempt symbol " + Body.getName());
     return Expr;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26496.77467.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161110/66387776/attachment.bin>


More information about the llvm-commits mailing list