This is an archive of the discontinued LLVM Phabricator instance.

[LTO][Legacy] Add new API to check presence of ctor/dtor functions
ClosedPublic

Authored by w2yehia on Jul 27 2021, 9:03 AM.

Details

Summary

On AIX, the linker needs to check whether a given lto_module_t contains any constructor/destructor functions, in order to implement the behavior of the -bcdtors:all flag. See https://www.ibm.com/docs/en/aix/7.2?topic=l-ld-command for the flag's documentation.
In llvm IR, constructor (destructor) functions are added to a special global array @llvm.global_ctors (@llvm.global_dtors).
However, because these two symbols are artificial, they are not visited during the symbol traversal (using the lto_module_get_[num_symbols|symbol_name|symbol_attribute] API).

This patch adds a new function to the libLTO interface that checks the presence of one or both of these two symbols.

Diff Detail

Event Timeline

w2yehia created this revision.Jul 27 2021, 9:03 AM
w2yehia requested review of this revision.Jul 27 2021, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2021, 9:03 AM
steven_wu requested changes to this revision.Jul 27 2021, 9:38 AM

Comment inline.

It would be good if you can find a way to write testcase.

llvm/lib/LTO/LTOModule.cpp
695

Can you simply this code a bit by using consume_front() on the name?

Also you need to check for nullptr for PointerUnion:

if (auto *GV = Sym.dyn_cast<>)
This revision now requires changes to proceed.Jul 27 2021, 9:38 AM
w2yehia edited the summary of this revision. (Show Details)Jul 27 2021, 9:52 AM
w2yehia updated this revision to Diff 362083.Jul 27 2021, 10:16 AM

address code review comment.

w2yehia updated this revision to Diff 362148.EditedJul 27 2021, 1:03 PM

Added testcase for LTOModule::hasCtorDtor()

@steven_wu FYI

steven_wu accepted this revision.Jul 27 2021, 2:42 PM

LGTM in general. Just two small comments inline. Thanks!

llvm/tools/llvm-lto/llvm-lto.cpp
404 ↗(On Diff #362148)

Can you update the comments here to reflect the current function?

420 ↗(On Diff #362148)

Can you make the output to stdout more verbose? Filename : {0|1} is not clear even for a testing tool.

This revision is now accepted and ready to land.Jul 27 2021, 2:42 PM
This revision was landed with ongoing or failed builds.Jul 28 2021, 5:43 AM
This revision was automatically updated to reflect the committed changes.
w2yehia updated this revision to Diff 362344.Jul 28 2021, 5:44 AM

commited version