This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Add -fvisibility hidden option to clang
ClosedPublic

Authored by yaxunl on Aug 29 2018, 8:49 AM.

Details

Summary

AMDGPU target need -fvisibility hidden option for clang to
work around a limitation of no PLT support, otherwise there is compilation
error at -O0.

Diff Detail

Repository
rL LLVM

Event Timeline

yaxunl created this revision.Aug 29 2018, 8:49 AM
tra added a comment.Aug 29 2018, 9:37 AM

Could you elaborate on what exactly is the problem this patch fixes?
I don't see how internalizing the symbols connects to PLTs. My understanding is that PLTs are used to provide stubs for symbols to be resolved by dynamic linker at runtime. AFAICT AMD does not use shared libs on device side. What do I miss?

In D51434#1217772, @tra wrote:

Could you elaborate on what exactly is the problem this patch fixes?
I don't see how internalizing the symbols connects to PLTs. My understanding is that PLTs are used to provide stubs for symbols to be resolved by dynamic linker at runtime. AFAICT AMD does not use shared libs on device side. What do I miss?

When AMDGPU backend generates ELF containing device ISA's, any non-kernel functions require
PLT support to be emitted to ELF. However AMDGPU backend currently does not support that,
which causes error.

Internalization will eliminate any non-kernel functions, therefore works around this limitation.

tra added a comment.Aug 29 2018, 10:26 AM

I could not find anything about PLTs in AMDGPU-ABI, nor could I find anything relevant on google.
I still have no idea why PLTs are required in this case. Without that info, the problem may as well be due to unintended requirement for PLT that this patch would hide.

I'm going to defer to someone more familiar with amdgpu to tell whether that's the right fix for the problem.

+Matt to confirm, but our executable format is a shared object and we eventually want to support preemptible symbols through the PLT. We already generate GOT entries for globals.

Currently we work around the lack of PLT support by internalizing all non-kernel functions, so for now this patch is required.

I have a patch to change the default visibility which I think is a better option

D51209 is the patch. I think HIP will need an additional patch, since I think it isn’t subclassing the amdgpu toolchain

D51209 is the patch. I think HIP will need an additional patch, since I think it isn’t subclassing the amdgpu toolchain

Yes since HIP has different toolchain. This does not affect kernel's visibility, right?

D51209 is the patch. I think HIP will need an additional patch, since I think it isn’t subclassing the amdgpu toolchain

Yes since HIP has different toolchain. This does not affect kernel's visibility, right?

It does, but the visibility of the kernel shouldn't matter

yaxunl updated this revision to Diff 163186.Aug 29 2018, 1:58 PM
yaxunl retitled this revision from [HIP] Add -amdgpu-internalize-symbols option to opt to [HIP] Add -fvisibility hidden option to clang.
yaxunl edited the summary of this revision. (Show Details)

Use -fvisibility hidden.

tra added inline comments.Aug 29 2018, 2:30 PM
lib/Driver/ToolChains/HIP.cpp
255 ↗(On Diff #163186)

Nit: You could collapse multiple push_back calls into a single append({...}):
CC1Args.append({"-fvisibility", "hidden"});

yaxunl updated this revision to Diff 163196.Aug 29 2018, 2:41 PM

Revised by Artem's comments.

arsenm added inline comments.Aug 29 2018, 10:11 PM
lib/Driver/ToolChains/HIP.cpp
256 ↗(On Diff #163196)

We should probably start subclassing the HIP toolchain from AMDGPU and share more of this

yaxunl added inline comments.Aug 30 2018, 7:37 AM
lib/Driver/ToolChains/HIP.cpp
256 ↗(On Diff #163196)

I'd like to defer the refactoring of HIP and AMDGPU toolchain to another patch. There are stuff in HIP toolchain which should go to AMDGPU toolchain. We need to sort out the relation between HIP and AMDGPU toolchain in that patch.

arsenm accepted this revision.Aug 30 2018, 7:38 AM
arsenm added inline comments.
lib/Driver/ToolChains/HIP.cpp
256 ↗(On Diff #163196)

Yes

This revision is now accepted and ready to land.Aug 30 2018, 7:38 AM
arsenm added inline comments.Aug 30 2018, 7:38 AM
lib/Driver/ToolChains/HIP.cpp
256 ↗(On Diff #163196)

I also have a patch refactoring the AMDGPU toolchain that would conflict

yaxunl added inline comments.Aug 30 2018, 7:41 AM
lib/Driver/ToolChains/HIP.cpp
256 ↗(On Diff #163196)

I will commit this patch then we will start reviewing your patch for refactoring AMDGPU toolchain.

This revision was automatically updated to reflect the committed changes.