On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between start of function and gp pointer into GOT. To make seal with such symbol we add new method addIgnoredStrong(). It adds ignored symbol with global binding to prevent the symbol substitution. The addIgnored call is not enough here because this call adds a weak symbol which might be substituted by symbol from shared library.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Is this behavior defined in the MIPS ABI, or is this just conventional?
Why addIgnored() didn't work? I think addIgnored() adds an absolute symbol to the symbol table, so it doesn't seem much different from this code.
test/ELF/mips-gp-disp.s | ||
---|---|---|
5 | Can you create this so file in this file from an assembly file, instead of checking in a binary file? |
MIPS ABI says nothing about emitting _gp_disp symbol into the symbol table. But almost all legacy shared library has this symbol in their symbol tables. I guess by historical reasons. If I use addIgnored call the IgnoreUndef symbol has STB_WEAK binding. So corresponding MipsGpDisp SymbolBody it can be substituted by _gp_disp symbol defined in such shared library.
When I add MipsGpDisp with STB_GLOBAL binding the symbol gets priority over symbols from shared libraries.
test/ELF/mips-gp-disp.s | ||
---|---|---|
5 | I can't. This so file has _gp_disp in the symbol table and emulates a legacy shared library. In fact we do not need to have _gp_disp in a symbol table and LLD cannot produce such shared library itself. |
Can you then add addIgnoredStrong() and IgnoredUndefStrong? The new ignored symbol is not actually specific to Mips or Mips _gp_disp symbol.
test/ELF/mips-gp-disp.s | ||
---|---|---|
5 | Ah, interesting, but there's still some way to create such .so file in an unusual way. For example, you can create an .so with a dummy symbol _XX_XXXX and replace it with _gp_disp using sed. |
By the way, do we still need to version of addIgnored method. What do you think, is it possible to always use the strong version?
Test fails under windows + msvs 2015:
21> FAIL: lld :: ELF/mips-gp-disp.s (213 of 1029)
21> **** TEST 'lld :: ELF/mips-gp-disp.s' FAILED ****
21> Script:
21> --
21> C:/access_softek/c_make_build_dir/Debug/bin\llvm-mc.EXE -filetype=obj -triple=mips-unknown-linux C:\access_softek\llvm\tools\lld\test\ELF/Inputs/mips-gp-disp-def.s -o C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.o
21> C:/access_softek/c_make_build_dir/Debug/bin\ld.lld.EXE -shared -o C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext-int.so C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.o
21> sed -e 's/XXXXXXXX/_gp_disp/g' C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext-int.so > C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.so
21> C:/access_softek/c_make_build_dir/Debug/bin\llvm-mc.EXE -filetype=obj -triple=mips-unknown-linux C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s -o C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.o
21> C:/access_softek/c_make_build_dir/Debug/bin\ld.lld.EXE -shared -o C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.so C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.o C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.so
21> C:/access_softek/c_make_build_dir/Debug/bin\llvm-readobj.EXE -symbols C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.so | C:/access_softek/c_make_build_dir/Debug/bin\FileCheck.EXE -check-prefix=INT-SO C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s
21> C:/access_softek/c_make_build_dir/Debug/bin\llvm-readobj.EXE -symbols C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.so | C:/access_softek/c_make_build_dir/Debug/bin\FileCheck.EXE -check-prefix=EXT-SO C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s
21> C:/access_softek/c_make_build_dir/Debug/bin\llvm-objdump.EXE -d -t C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.so | C:/access_softek/c_make_build_dir/Debug/bin\FileCheck.EXE -check-prefix=DIS C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s
21> --
21> Exit Code: 1
21>
21> Command Output (stdout):
21> --
21> Command 0: "C:/access_softek/c_make_build_dir/Debug/bin\llvm-mc.EXE" "-filetype=obj" "-triple=mips-unknown-linux" "C:\access_softek\llvm\tools\lld\test\ELF/Inputs/mips-gp-disp-def.s" "-o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.o"
21> Command 0 Result: 0
21> Command 0 Output:
21>
21>
21> Command 0 Stderr:
21>
21>
21> Command 1: "C:/access_softek/c_make_build_dir/Debug/bin\ld.lld.EXE" "-shared" "-o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext-int.so" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.o"
21> Command 1 Result: 0
21> Command 1 Output:
21>
21>
21> Command 1 Stderr:
21>
21>
21> Command 2: "sed" "-e" "s/XXXXXXXX/_gp_disp/g" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext-int.so"
21> Command 2 Result: 0
21> Command 2 Output:
21> None
21>
21> Command 2 Stderr:
21>
21>
21> Command 3: "C:/access_softek/c_make_build_dir/Debug/bin\llvm-mc.EXE" "-filetype=obj" "-triple=mips-unknown-linux" "C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s" "-o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.o"
21> Command 3 Result: 0
21> Command 3 Output:
21>
21>
21> Command 3 Stderr:
21>
21>
21> Command 4: "C:/access_softek/c_make_build_dir/Debug/bin\ld.lld.EXE" "-shared" "-o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.so" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext.so"
21> Command 4 Result: 1
21> Command 4 Output:
21>
21>
21> Command 4 Stderr:
21> Invalid data was encountered while parsing the file
21> Command 3: "C:/access_softek/c_make_build_dir/Debug/bin\llvm-mc.EXE" "-filetype=obj" "-triple=mips-unknown-linux" "C:\access_softek\llvm\tools\lld\test\ELF\mips-gp-disp.s" "-o" "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp.o"
21> Command 3 Result: 0
21> Command 3 Output:
Could you please send "C:\access_softek\c_make_build_dir\tools\lld\test\ELF\Output\mips-gp-disp.s.tmp-ext-int.so"? I guess sed corrupts the file for some reason.
Can you add a comment on why you are using "Strong" as you described before?