This is an archive of the discontinued LLVM Phabricator instance.

[AIX][Driver] Implement -mxcoff-build-id option.
ClosedPublic

Authored by w2yehia on Mar 20 2023, 8:41 AM.

Details

Summary

The -mxcoff-build-id=0xHEXSTRING option is an alternative to the
--build-id=0xHEXSTRING linker option that is not currently available in
the AIX linker.

If HEXSTRING is an odd number of hex digits then a '0' character is prepended.
The characters ':' and '-' are not allowed (unlike the GNU linker option).
The given build-id will be saved in the string table of the loader section.

A subsequent commit will teach the profile runtime to read and use the embedded id.

Diff Detail

Event Timeline

w2yehia created this revision.Mar 20 2023, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 8:41 AM
Herald added a subscriber: wenlei. · View Herald Transcript
w2yehia requested review of this revision.Mar 20 2023, 8:41 AM
w2yehia updated this revision to Diff 506676.Mar 20 2023, 12:03 PM
w2yehia edited the summary of this revision. (Show Details)

add "<0xHEXSTRING>" to the option documentation.

qiongsiwu1 edited reviewers, added: qiongsiwu1; removed: qiongsiwu.Mar 20 2023, 12:29 PM
w2yehia updated this revision to Diff 506683.Mar 20 2023, 12:35 PM
w2yehia updated this revision to Diff 506685.Mar 20 2023, 12:46 PM

add new test

Is there any reason to require an even number of hex digits? Or to convert the hex string to lower case?

clang/test/Driver/xcoff-build-id.c
7

You could add a test where the build id is specified with upper case hex digits to ensure they're converted successfully.

w2yehia added inline comments.Mar 22 2023, 1:42 PM
clang/test/Driver/xcoff-build-id.c
7

need to test that the -bdbg:ldrinfo linker flag we pass to the linker comes before any user specified linker options (or at least before any user specified -bdbg:ldrinfo flags)

Is there any reason to require an even number of hex digits? Or to convert the hex string to lower case?

only that's it's easier to convert ascii to number (atoi) by anyone reading the info and needing it in number form (such as the PGO runtime)

clang/test/Driver/xcoff-build-id.c
7

that's covered on line 2

qiongsiwu1 accepted this revision.Mar 23 2023, 1:09 PM

LGTM! Thanks!

This revision is now accepted and ready to land.Mar 23 2023, 1:09 PM
clang/lib/Driver/ToolChains/AIX.cpp
152

nit: there are some notes in getSpelling() about why getAsString is preferred I believe

154–158

minor nit: I find this a little more readable and it avoids the empty append

w2yehia updated this revision to Diff 508199.Mar 24 2023, 12:49 PM

Fix bug: StringRef::lower() returns a std::string as a temporary, and Twine doesn't own the memory of the substrings.
The temporary should be used in the same C++ statement so that there's no lifetime issues.

w2yehia marked 2 inline comments as done.Mar 25 2023, 10:54 PM

Let's document the option as well under: https://clang.llvm.org/docs/ClangCommandLineReference.html#powerpc

I tried changing the Option group from m__Group to m_ppc_Features_Group but that causes clang/llvm to write the flag as an attribute in the IR, causing compilation issues.
Also I noticed that m_Group is a CompileOnly_Group, and so I changed the group to the more appropriate Link_Group.

clang/lib/Driver/ToolChains/AIX.cpp
152

not in this case; here's the diagnostics I get with your suggestion:

clang: error: unsupported argument 'ff' to option '-mxcoff-build-id=ff'
w2yehia updated this revision to Diff 508378.Mar 25 2023, 10:54 PM
w2yehia marked an inline comment as done.
daltenty accepted this revision.Mar 27 2023, 7:48 AM

LGTM, thanks!

w2yehia marked an inline comment as done.Mar 27 2023, 8:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 8:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript