Page MenuHomePhabricator

[AIX][driver] Include crti[_64].o and -bcdtors also for C language link invocations by default
ClosedPublic

Authored by Xiangling_L on Nov 12 2020, 8:18 AM.

Details

Summary

In order to support attribute((constructor)) and attribute((destructor)), which is used by various LLVM non-C++ runtime components, AIX will include crti[_64].o and -bcdtors for C language link invocations by default.

Diff Detail

Event Timeline

Xiangling_L created this revision.Nov 12 2020, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2020, 8:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Xiangling_L requested review of this revision.Nov 12 2020, 8:18 AM
daltenty added inline comments.Nov 12 2020, 12:59 PM
clang/lib/Driver/ToolChains/AIX.cpp
136–137

I think that rather that adding CC, we should just pull the if and unconditionally link crti.o. This is consistent with what is done on other platforms and since the llvm.global_c/dtors are generally allowable in the IR, we might see them in more than just the two driver scenarios suggested here.

144

Ditto the previous comment.

Xiangling_L added inline comments.Nov 12 2020, 1:59 PM
clang/lib/Driver/ToolChains/AIX.cpp
136–137

we should just pull the if and unconditionally link crti.o. ...we might see them in more than just the two driver scenarios suggested here.

I was thinking to use the code to document what exactly happen is under c++ and c mode we link crti.o. But I think it makes sense to just remove if as you said. But we can indicate it's something for C and CXX mode only? Cuz as far as I know, there are c++, c, preprocessor, cl and flang driver mode. I think it only make sense for us to see static init functions generated in IR in c++ and c mode on AIX?

daltenty added inline comments.Nov 12 2020, 6:56 PM
clang/lib/Driver/ToolChains/AIX.cpp
136–137

These mode flags don't exactly correspond to input languages though, so it's not quite right to say this is "something for C and CXX mode only" (i.e. CXX isn't defined as "C++" mode, it's "behave similar to g++").

For example, it seems like if someone tired to link a mixed C and Fortran program using --driver-mode=flang, the static init in the C portion would stop working because we'd omit crit.o. I don't know if there is an advantage to being more specific in this case, and it definitely seems like it could run us into problems.

Remove the if condition and tweak the comments;

daltenty accepted this revision.Nov 13 2020, 8:44 AM

LGTM, thanks!

This revision is now accepted and ready to land.Nov 13 2020, 8:44 AM