This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][AIX] Implement XCOFF exported visibility
ClosedPublic

Authored by daltenty on Apr 18 2022, 10:57 AM.

Details

Summary

[LLVM] Add exported visibility style for XCOFF

For the AIX linker, under default options, global or weak symbols which
have no visibility bits set to zero (i.e. no visibility, similar to ELF
default) are only exported if specified on an export list provided to
the linker. So AIX has an additional visibility style called
"exported" which indicates to the linker that the symbol should
be explicitly globally exported.

This change maps "dllexport" in the LLVM IR to correspond to XCOFF
exported as we feel this best models the intended semantic (discussion
on the discourse RFC thread: https://discourse.llvm.org/t/rfc-adding-exported-visibility-style-to-the-ir-to-model-xcoff-exported-visibility/61853)
and allows us to enable writing this visibility for the AIX target
in the assembly path.

Diff Detail

Event Timeline

daltenty created this revision.Apr 18 2022, 10:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2022, 10:57 AM
daltenty requested review of this revision.Apr 18 2022, 10:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2022, 10:57 AM
DiggerLin added a comment.EditedApr 18 2022, 1:57 PM

we need to change the following functions to deal with MCSA_Exported

  1. MCWasmStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) too .
  2. MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym, MCSymbolAttr Attribute)
llvm/lib/MC/MCAsmStreamer.cpp
769

change to
case MCSA_Cold:

// Assemblers currently do not support a .cold directive.

case MCSA_Exported:

 // Non-AIX assemblers currently do not support exported visibility.
return false;

?

DiggerLin added inline comments.Apr 18 2022, 2:16 PM
llvm/lib/IR/AsmWriter.cpp
3155 ↗(On Diff #423410)

if I understand correct. this is for IR generate, if add it now, I do not think we can have a test case for it now ? It maybe better to add when implement the frontend.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1905

maybe better to change to
// TODO: "internal" Visibility needs to go here.
case GlobalValue::ExportedVisibility:

VisibilityAttr = MAI->getExportedVisibilityAttr();
break;
daltenty marked 2 inline comments as done.Apr 19 2022, 3:51 PM
daltenty added inline comments.
llvm/lib/IR/AsmWriter.cpp
3155 ↗(On Diff #423410)

Thanks for catching that, I've added a seperate unit test since none seems to exist currently.

daltenty updated this revision to Diff 423757.Apr 19 2022, 3:52 PM

Address review comments

DiggerLin added a comment.EditedApr 20 2022, 10:46 AM

we need to change the following functions to deal with MCSA_Exported

MCWasmStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) too .
MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym, MCSymbolAttr Attribute)

It looks this two comments not be addressed.

daltenty retitled this revision from [LLVM] Add exported visibility-style to IR for XCOFF to [LLVM][AIX] Implement XCOFF exported visibility.Apr 22 2022, 10:37 AM
daltenty edited the summary of this revision. (Show Details)
daltenty updated this revision to Diff 424528.Apr 22 2022, 10:40 AM

Update the patch based on feedback on the RFC (https://discourse.llvm.org/t/rfc-adding-exported-visibility-style-to-the-ir-to-model-xcoff-exported-visibility/61853/8). There seem to be limited visibility bits, and the implementation has kind of reserved space for internal, so adding exported may cause problems. On the other hand dllexport appears to match the semantic and currently only be used as a marker to indicate to some passes that we should preserve the symbol since it will be exported from shared objects (which is exactly what we want too), so I've updated the implementation as suggested to use dllexport instead.

daltenty updated this revision to Diff 424926.Apr 25 2022, 8:56 AM

Make MCWasmStreamer ignore MCSA_Exported

This revision is now accepted and ready to land.Apr 26 2022, 11:30 AM
daltenty edited the summary of this revision. (Show Details)Apr 28 2022, 6:47 AM
daltenty edited the summary of this revision. (Show Details)
daltenty updated this revision to Diff 425868.Apr 28 2022, 11:51 AM

Make assert for mixed non-export visibility and dllexport a fatal error

This revision was landed with ongoing or failed builds.Apr 28 2022, 11:56 AM
This revision was automatically updated to reflect the committed changes.