This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] Prevent substitution of _gp_disp symbol
ClosedPublic

Authored by atanasyan on Jan 11 2016, 1:53 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 44548.Jan 11 2016, 1:53 PM
atanasyan retitled this revision from to [ELF][MIPS] Prevent substitution of _gp_disp symbol.
atanasyan updated this object.
atanasyan added reviewers: ruiu, rafael.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
atanasyan added a subscriber: llvm-commits.
ruiu edited edge metadata.Jan 11 2016, 2:00 PM

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
6

Can you create this so file in this file from an assembly file, instead of checking in a binary file?

In D16084#324046, @ruiu wrote:

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.

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
6

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.

ruiu added a comment.Jan 11 2016, 2:24 PM

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
6

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.

atanasyan updated this revision to Diff 44565.Jan 11 2016, 3:13 PM
atanasyan updated this object.
atanasyan edited edge metadata.
  • Add new general addIgnoredStrong() method
  • Do not use binary files in the test
ruiu accepted this revision.Jan 11 2016, 3:20 PM
ruiu edited edge metadata.

LGTM

ELF/Driver.cpp
308

Can you add a comment on why you are using "Strong" as you described before?

test/ELF/Inputs/mips-gp-disp-def.s
1

Please add a comment why we are doing this (that we can't create a shared object file containing the special symbol.)

This revision is now accepted and ready to land.Jan 11 2016, 3:20 PM
In D16084#324213, @ruiu wrote:

LGTM

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?

This revision was automatically updated to reflect the committed changes.
grimar added a subscriber: grimar.Jan 12 2016, 2:24 AM

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

Test fails under windows + msvs 2015:

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.

The problem with failed test case on Windows fixed at rL257471.