Merging r324467 and r324468:
------------------------------------------------------------------------
r324467 | atanasyan | 2018-02-07 11:02:49 +0100 (Wed, 07 Feb 2018) | 9 lines
[ELF][MIPS] Ignore incorrect version definition index for _gp_disp symbol
MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
version definition index to it. This value means 'unversioned local
symbol' while _gp_disp is a section global symbol. We have to handle
this bug in the LLD because BFD linker is used for building MIPS
toolchain libraries.
Differential revision: https://reviews.llvm.org/D42486
------------------------------------------------------------------------
------------------------------------------------------------------------
r324468 | atanasyan | 2018-02-07 11:14:22 +0100 (Wed, 07 Feb 2018) | 1 line
[ELF][MIPS] Mark the test as required MIPS target support. NFC
------------------------------------------------------------------------
llvm-svn: 324471
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index f514870..ccf4b3d 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -856,6 +856,14 @@
continue;
}
+ if (Config->EMachine == EM_MIPS) {
+ // FIXME: MIPS BFD linker puts _gp_disp symbol into DSO files
+ // and incorrectly assigns VER_NDX_LOCAL to this section global
+ // symbol. Here is a workaround for this bug.
+ if (Versym && VersymIndex == VER_NDX_LOCAL && Name == "_gp_disp")
+ continue;
+ }
+
const Elf_Verdef *Ver = nullptr;
if (VersymIndex != VER_NDX_GLOBAL) {
if (VersymIndex >= Verdefs.size() || VersymIndex == VER_NDX_LOCAL) {
diff --git a/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s b/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s
new file mode 100644
index 0000000..42bd32a
--- /dev/null
+++ b/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s
@@ -0,0 +1,14 @@
+# Source file for mips-gp-dips-corrupt-ver.so
+#
+# % cat gpdisp.ver
+# LLD_1.0.0 { global: foo; };
+#
+# % as mips-gp-dips-corrupt-ver.s -o mips-gp-dips-corrupt-ver.o
+# % ld -shared -o mips-gp-dips-corrupt-ver.so \
+# --version-script gpdisp.ver mips-gp-dips-corrupt-ver.o
+
+ .global foo
+ .text
+foo:
+ lui $t0, %hi(_gp_disp)
+ addi $t0, $t0, %lo(_gp_disp)
diff --git a/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so b/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so
new file mode 100755
index 0000000..289ffa5
--- /dev/null
+++ b/lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so
Binary files differ
diff --git a/lld/test/ELF/mips-gp-disp-ver.s b/lld/test/ELF/mips-gp-disp-ver.s
new file mode 100644
index 0000000..134a056
--- /dev/null
+++ b/lld/test/ELF/mips-gp-disp-ver.s
@@ -0,0 +1,15 @@
+# MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
+# version definition index to it. This value means 'unversioned local symbol'
+# while _gp_disp is a section global symbol. We have to handle this bug
+# in the LLD because BFD linker is used for building MIPS toolchain
+# libraries. This test checks such handling.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o %S/Inputs/mips-gp-dips-corrupt-ver.so
+
+# REQUIRES: mips
+
+ .global __start
+ .text
+__start:
+ lw $t0, %got(foo)($gp)