This is an archive of the discontinued LLVM Phabricator instance.

[AIX] Fix Link Issue when `-fprofile-update=[atomic|prefer-atomic]` is in Effect
ClosedPublic

Authored by qiongsiwu1 on Aug 29 2023, 1:48 PM.

Details

Summary

https://reviews.llvm.org/D157280 enabled -fprofile-update for -fprofile-generate, but omitted adding -latomic to the linker command on AIX. This omission causes linking to fail due to an undefined symbol. This patch fixes the link error.

Diff Detail

Event Timeline

qiongsiwu1 created this revision.Aug 29 2023, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 1:48 PM
qiongsiwu1 requested review of this revision.Aug 29 2023, 1:48 PM
qiongsiwu1 added inline comments.Aug 29 2023, 1:51 PM
clang/lib/Driver/ToolChains/AIX.cpp
440

This check here is copied from https://github.com/llvm/llvm-project/blob/77596e6b167bf0a5efa790597d6b75ac5e685b55/clang/lib/Driver/ToolChains/Clang.cpp#L867, and I don't think it is good to copy this particular code over because we are doing the same check twice at different places and the code can go out of sync.

May I get some suggestions to avoid duplicating the code? Thanks!

MaskRay added inline comments.Aug 29 2023, 3:16 PM
clang/lib/Driver/ToolChains/AIX.cpp
440

This seems ok to me. You can also use != "single" instead.

getLastArgNoClaim is probably slightly better.

clang/test/Driver/fprofile-update.c
17

The idiom is to use --target=.... This driver decision is not dependent on what OS the host runs, so %if system-aix should be avoided.

Address code review feedback.

qiongsiwu1 marked 2 inline comments as done.Aug 29 2023, 4:49 PM
qiongsiwu1 added inline comments.
clang/test/Driver/fprofile-update.c
17

Ah yes thanks for the feedback. Fixed!

qiongsiwu1 marked an inline comment as done.Aug 30 2023, 7:57 AM
w2yehia accepted this revision.Aug 30 2023, 12:33 PM
This revision is now accepted and ready to land.Aug 30 2023, 12:33 PM
w2yehia added inline comments.Aug 30 2023, 12:35 PM
clang/test/Driver/fprofile-update.c
18

not sure if it's typical to also add a negative test that -latomic is not added by default or with "single" suboption. I'll leave it to you to decide.

Address code review. Thanks for the input @w2yehia !

qiongsiwu1 marked an inline comment as done.Aug 30 2023, 3:16 PM
This revision was landed with ongoing or failed builds.Aug 30 2023, 4:21 PM
This revision was automatically updated to reflect the committed changes.