[clang] da92f2f - [AIX][Driver] Implement -mxcoff-build-id option
Wael Yehia via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 27 08:37:47 PDT 2023
Author: Wael Yehia
Date: 2023-03-27T15:36:41Z
New Revision: da92f2fb33c4e5fc570a51b0615e3d30a5b0bf8f
URL: https://github.com/llvm/llvm-project/commit/da92f2fb33c4e5fc570a51b0615e3d30a5b0bf8f
DIFF: https://github.com/llvm/llvm-project/commit/da92f2fb33c4e5fc570a51b0615e3d30a5b0bf8f.diff
LOG: [AIX][Driver] Implement -mxcoff-build-id option
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.
Reviewed By: daltenty, qiongsiwu1, stephenpeckham
Differential Revision: https://reviews.llvm.org/D146431
Added:
clang/test/Driver/xcoff-build-id.c
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/AIX.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 2f81f60a63995..5d2089e6b3edc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3905,6 +3905,8 @@ defm zvector : BoolFOption<"zvector",
def mzvector : Flag<["-"], "mzvector">, Alias<fzvector>;
def mno_zvector : Flag<["-"], "mno-zvector">, Alias<fno_zvector>;
+def mxcoff_build_id_EQ : Joined<["-"], "mxcoff-build-id=">, Group<Link_Group>, MetaVarName<"<0xHEXSTRING>">,
+ HelpText<"On AIX, request creation of a build-id string, \"0xHEXSTRING\", in the string table of the loader section inside the linked binary">;
def mignore_xcoff_visibility : Flag<["-"], "mignore-xcoff-visibility">, Group<m_Group>,
HelpText<"Not emit the visibility attribute for asm in AIX OS or give all symbols 'unspecified' visibility in XCOFF object file">,
Flags<[CC1Option]>;
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 711e8619d0a79..0ac261b548718 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -143,6 +143,22 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.hasArg(options::OPT_coverage))
CmdArgs.push_back("-bdbg:namedsects:ss");
+ if (Arg *A =
+ Args.getLastArg(clang::driver::options::OPT_mxcoff_build_id_EQ)) {
+ StringRef BuildId = A->getValue();
+ if (BuildId[0] != '0' || BuildId[1] != 'x' ||
+ BuildId.find_if_not(llvm::isHexDigit, 2) != StringRef::npos)
+ ToolChain.getDriver().Diag(diag::err_drv_unsupported_option_argument)
+ << A->getSpelling() << BuildId;
+ else {
+ std::string LinkerFlag = "-bdbg:ldrinfo:xcoff_binary_id:0x";
+ if (BuildId.size() % 2) // Prepend a 0 if odd number of digits.
+ LinkerFlag += "0";
+ LinkerFlag += BuildId.drop_front(2).lower();
+ CmdArgs.push_back(Args.MakeArgString(LinkerFlag));
+ }
+ }
+
// Specify linker output file.
assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
if (Output.isFilename()) {
diff --git a/clang/test/Driver/xcoff-build-id.c b/clang/test/Driver/xcoff-build-id.c
new file mode 100644
index 0000000000000..5f12f5b737716
--- /dev/null
+++ b/clang/test/Driver/xcoff-build-id.c
@@ -0,0 +1,14 @@
+// RUN: touch %t.o
+// RUN: %clang --target=powerpc64-ibm-aix -### %t.o -mxcoff-build-id=0x12 2>&1 | FileCheck %s
+// Test that:
+// 1) our ldrinfo flag comes before any user specified ldrinfo flag;
+// 2) upper case hex digits are converted to lower case;
+// 3) a zero is added when odd number of digits is specified in the HEXSTRING.
+// RUN: %clang --target=powerpc-ibm-aix -### %t.o -Wl,-bdbg:ldrinfo:FOO -mxcoff-build-id=0x011ffFF 2>&1 | FileCheck %s --check-prefix=OTHER
+
+// RUN: %clang --target=powerpc-ibm-aix -### %t.o -mxcoff-build-id=ff 2>&1 | FileCheck %s --check-prefix=BAD_INPUT
+// RUN: %clang --target=powerpc-ibm-aix -### %t.o -mxcoff-build-id=0x0z 2>&1 | FileCheck %s --check-prefix=BAD_INPUT
+
+CHECK: "-bdbg:ldrinfo:xcoff_binary_id:0x12"
+OTHER: "-bdbg:ldrinfo:xcoff_binary_id:0x0011ffff" {{.*}} "-bdbg:ldrinfo:FOO"
+BAD_INPUT: clang: error: unsupported argument {{.*}} to option '-mxcoff-build-id='
More information about the cfe-commits
mailing list