From 85815a31491561ba1ac9042c55d5312d2c98eb56 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 7 Feb 2018 10:02:49 +0000 Subject: [PATCH] [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 llvm-svn: 324467 --- lld/ELF/InputFiles.cpp | 8 ++++++++ lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s | 14 ++++++++++++++ lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so | Bin 0 -> 2160 bytes lld/test/ELF/mips-gp-disp-ver.s | 13 +++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s create mode 100755 lld/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so create mode 100644 lld/test/ELF/mips-gp-disp-ver.s diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 4edabc578667..457dc7dedf9f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -862,6 +862,14 @@ template void SharedFile::parseRest() { 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 000000000000..42bd32a1e73a --- /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 0000000000000000000000000000000000000000..289ffa538f0c2b5480b0139666f06a4255cd9fec GIT binary patch literal 2160 zcmb7FOHUJF6ur|zsen9u#Y7ewSr7~(L`{scXpz=nim0H8iODdf51L44GBX%i(ZrQ2 zS@IKH@-z4e{0v=~u+Y?VzDH>*F?!RJ``vrb_defrzfdYVDMvb%mMq#xq+9U!MKae# zCfK?u8JUrB84FQF?X(Nv2r&R;QHMF`WT9%dPEOZ^?kvLXF_q#NW)+9dYpclXzb0Qwu!wb57s~MN-G`8F=n#7}x|x0PGoOgLQ{`j}AQe zl7a_c1fG1xlkg+(m*7X?FEb9>?VlJT2mgya_-}}@*Z(%&5!b}|E&ytN_h z2;h2o*5{bg1TUZCT~+sk#)O^&cc;z?8)<(>dJOAs!Lv^O8@6eax_%q|4;h>Oyz>@g z91QtWef0-@@!g)d76jteL$A_^L-A@!^3TXxkJ#u#-xp%u7pCJoR&{EwW2jSySfgH#qwjy% z>IF6O$83L7pSCeJ#rhq~H~PZ2sYhRr!BJ-PRp`-&$Vy2hD5Vx||^miIt;%@u#whA$Z_DLizMC3xwaU*E<1YSj4 z^-A1&km!n^BvGThn^a?al>g#ygd(#bQgf#U{4QFfRv6EMM_uvTjVo1J?dDOFjPC)K z2mLC|9GM)P(k{nb1k|?`oD&VnnH-$ram*!v`op}`yVATJ4>`rddgK`ZsVd$v93Y#3 zHTwo%;hWq>5`FnT)El{m*t{X;6+HV52PdZ?4^cCFvu{wE$Z>4ssb{5WuE&~fCrI$n z)c*_I0b-tmHS)OMJ