This is an archive of the discontinued LLVM Phabricator instance.

[ELF][PPC32] Make R_PPC32_PLTREL retain .got
ClosedPublic

Authored by kernigh on Dec 2 2021, 12:08 PM.

Details

Summary

PLT usage needs the first 12 bytes of the .got section. We need to keep .got and
DT_GOT_PPC even if .got/_GLOBAL_OFFSET_TABLE_ are not referenced (large PIC code
may only reference .got2), which is the case in OpenBSD's ld.so, leading
to a misleading error, "unsupported insecure BSS PLT object".

Fix this by adding R_PPC32_PLTREL to the list of hasGotOffRel.

Diff Detail

Event Timeline

kernigh created this revision.Dec 2 2021, 12:08 PM
kernigh requested review of this revision.Dec 2 2021, 12:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2021, 12:08 PM

I don't have commit access to LLVM.

You might wonder why this diff adds R_PPC32_PLTREL but not R_PPC64_CALL_PLT. My problem (where .got is missing) happened only in 32-bit code. Code that calls the plt must set register r30 in 32-bit code, or r2 in 64-bit. Most 64-bit code sets r2 = .TOC. = address of .got; LLD might keep .got because it sees this .TOC. reference. 32-bit -fPIC code can set r30 = somewhere in .got2, so there is no reference to .got, and LLD can discard .got unless we add R_PPC32_PLTREL to the list.

MaskRay updated this revision to Diff 391479.Dec 2 2021, 3:26 PM
MaskRay retitled this revision from [ELF][PowerPC] Don't discard .got if 32-bit plt needs it to [ELF][PPC32] Make R_PPC32_PLTREL retain .got.
MaskRay edited the summary of this revision. (Show Details)

Fix tests. Simplify new test.

I don't have commit access to LLVM.

You might wonder why this diff adds R_PPC32_PLTREL but not R_PPC64_CALL_PLT. My problem (where .got is missing) happened only in 32-bit code. Code that calls the plt must set register r30 in 32-bit code, or r2 in 64-bit. Most 64-bit code sets r2 = .TOC. = address of .got; LLD might keep .got because it sees this .TOC. reference. 32-bit -fPIC code can set r30 = somewhere in .got2, so there is no reference to .got, and LLD can discard .got unless we add R_PPC32_PLTREL to the list.

Seems that OpenBSD ld.so doesnot reference .got / _GLOBAL_OFFSET_TABLE_ at all. Other ld.so implementations all reference .got/_GLOBAL_OFFSET_TABLE_ somehow.

MaskRay accepted this revision.Dec 2 2021, 3:27 PM

LGTM.

This revision is now accepted and ready to land.Dec 2 2021, 3:27 PM
This revision was landed with ongoing or failed builds.Dec 2 2021, 3:28 PM
This revision was automatically updated to reflect the committed changes.