[PATCH] D72943: [ELF] Allow R_PLT_PC (R_PC) to a hidden undefined weak symbol

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 13:07:41 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ab89c3c5df8: [ELF] Allow R_PLT_PC (R_PC) to a hidden undefined weak symbol (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72943/new/

https://reviews.llvm.org/D72943

Files:
  lld/ELF/Relocations.cpp
  lld/test/ELF/weak-undef-hidden.s


Index: lld/test/ELF/weak-undef-hidden.s
===================================================================
--- lld/test/ELF/weak-undef-hidden.s
+++ lld/test/ELF/weak-undef-hidden.s
@@ -2,6 +2,11 @@
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
 // RUN: ld.lld %t.o -o %t.so -shared
 // RUN: llvm-readobj -r -S --section-data %t.so | FileCheck %s
+// RUN: ld.lld %t.o -o %t -pie
+// RUN: llvm-readobj -r -S --section-data %t | FileCheck %s
+
+/// This is usually guarded with a comparison. Don't report an error.
+call g
 
 .data
 .weak g
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -408,6 +408,14 @@
 
   assert(absVal && relE);
 
+  // Allow R_PLT_PC (optimized to R_PC here) to a hidden undefined weak symbol
+  // in PIC mode. This is a little strange, but it allows us to link function
+  // calls to such symbols (e.g. glibc/stdlib/exit.c:__run_exit_handlers).
+  // Normally such a call will be guarded with a comparison, which will load a
+  // zero from the GOT.
+  if (sym.isUndefWeak())
+    return true;
+
   // We set the final symbols values for linker script defined symbols later.
   // They always can be computed as a link time constant.
   if (sym.scriptDefined)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72943.238870.patch
Type: text/x-patch
Size: 1316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200117/6474c833/attachment.bin>


More information about the llvm-commits mailing list