Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3905,6 +3905,8 @@ def mzvector : Flag<["-"], "mzvector">, Alias; def mno_zvector : Flag<["-"], "mno-zvector">, Alias; +def mxcoff_build_id_EQ : Joined<["-"], "mxcoff-build-id=">, Group, MetaVarName<"<0xHEXSTRING>">, + HelpText<"Request creation of a build-id string, \"0xHEXSTRING\", inside the linked binary">; def mignore_xcoff_visibility : Flag<["-"], "mignore-xcoff-visibility">, Group, HelpText<"Not emit the visibility attribute for asm in AIX OS or give all symbols 'unspecified' visibility in XCOFF object file">, Flags<[CC1Option]>; Index: clang/lib/Driver/ToolChains/AIX.cpp =================================================================== --- clang/lib/Driver/ToolChains/AIX.cpp +++ clang/lib/Driver/ToolChains/AIX.cpp @@ -143,6 +143,21 @@ 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 { + bool PrependZero = BuildId.size() % 2; // To make it even # of digits. + CmdArgs.push_back(Args.MakeArgString( + llvm::Twine("-bdbg:ldrinfo:xcoff_binary_id:0x") + + (PrependZero ? "0" : "") + BuildId.drop_front(2).lower())); + } + } + // Specify linker output file. assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); if (Output.isFilename()) { Index: clang/test/Driver/xcoff-build-id.c =================================================================== --- /dev/null +++ clang/test/Driver/xcoff-build-id.c @@ -0,0 +1,8 @@ +// RUN: touch %t.o +// RUN: %clang --target=powerpc-ibm-aix -### %t.o -mxcoff-build-id=0x0011ffFF 2>&1 | FileCheck %s +// RUN: %clang --target=powerpc-ibm-aix -### %t.o -mxcoff-build-id=0x011ffff 2>&1 | FileCheck %s +// 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:0x0011ffff" +BAD_INPUT: clang: error: unsupported argument {{.*}} to option '-mxcoff-build-id='