Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ CUDA Support
AIX Support
^^^^^^^^^^^

- The driver default for the linker flag `-bcdtors` now defaults to `mbr`
(instead of `all`) which only extracts static init from archive members which
would otherwise be referenced.
(See https://www.ibm.com/docs/en/aix/7.2.0?topic=l-ld-command for details).

NetBSD Support
^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// language link invocations. This has to come before AddLinkerInputs as the
// implied option needs to precede any other '-bcdtors' settings or
// '-bnocdtors' that '-Wl' might forward.
CmdArgs.push_back("-bcdtors:all:0:s");
CmdArgs.push_back("-bcdtors:mbr:0:s");

if (Args.hasArg(options::OPT_rpath)) {
for (const auto &bopt : Args.getAllArgValues(options::OPT_b))
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/aix-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@
// CHECK-LD32-ARG-ORDER: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-ARG-ORDER: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-ARG-ORDER: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-ARG-ORDER: "-bcdtors:all:0:s"
// CHECK-LD32-ARG-ORDER: "-bcdtors:mbr:0:s"
// CHECK-LD32-ARG-ORDER: "-bnocdtors"
// CHECK-LD32-ARG-ORDER-NOT: "-bcdtors:all:0:s"
// CHECK-LD32-ARG-ORDER-NOT: "-bcdtors:mbr:0:s"
// CHECK-LD32-ARG-ORDER-NOT: "-lc++"
// CHECK-LD32-ARG-ORDER-NOT: "-lc++abi"
// CHECK-LD32-ARG-ORDER: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
Expand All @@ -382,9 +382,9 @@
// CHECK-LD32-CXX-ARG-ORDER: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-CXX-ARG-ORDER: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-CXX-ARG-ORDER: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-CXX-ARG-ORDER: "-bcdtors:all:0:s"
// CHECK-LD32-CXX-ARG-ORDER: "-bcdtors:mbr:0:s"
// CHECK-LD32-CXX-ARG-ORDER: "-bnocdtors"
// CHECK-LD32-CXX-ARG-ORDER-NOT: "-bcdtors:all:0:s"
// CHECK-LD32-CXX-ARG-ORDER-NOT: "-bcdtors:mbr:0:s"
// CHECK-LD32-CXX-ARG-ORDER: "-lc++"
// CHECK-LD32-CXX-ARG-ORDER: "-lc++abi"
// CHECK-LD32-CXX-ARG-ORDER: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/profile/InstrProfilingPlatformAIX.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void __llvm_profile_register_names_function(void *NamesStart,
// reference symbols from the profile library (for example when no files were
// compiled with -fprofile-generate). That's because these symbols are kept
// alive through references in constructor functions that are always live in the
// default linking model on AIX (-bcdtors:all). The __start_SECNAME and
// `-bcdtors:all` linking model on AIX. The __start_SECNAME and
// __stop_SECNAME symbols are only resolved by the linker when the SECNAME
// section exists. So for the scenario where the user objects have no such
// section (i.e. when they are compiled with -fno-profile-generate), we always
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/profile/instrprof-merge-entry-cover.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ __attribute__((noinline)) void foo(char c) {
__attribute__((noinline)) void bar(int M) { g += M; }

int main(int argc, const char *argv[]) {
__llvm_profile_test_initialize();
int i;
if (argc < 4)
return 1;
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/profile/instrprof-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void foo(char c) {
void bar(int M) { g += M; }

int main(int argc, const char *argv[]) {
__llvm_profile_test_initialize();
int i;
if (argc < 4)
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s

#include "profile_test.h"

int __llvm_profile_runtime = 0;
int __llvm_profile_register_write_file_atexit(void);
void __llvm_profile_set_filename(const char *);
int main(int argc, const char *argv[]) {
__llvm_profile_test_initialize();
__llvm_profile_register_write_file_atexit();
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
if (argc < 2)
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/test/profile/profile_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@
# define ALIGNED(x) __attribute__((aligned(x)))
#endif

inline void __llvm_profile_test_initialize() {
// This is a no-op on most platforms, but on AIX it forces the linker to
// keep the start/stop stub data for the runtime. Normally this data is
// referenced by pulling in `__llvm_profile_runtime` from the runtime but
// some tests explicitly supress that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to give some context about __llvm_profile_keep (no need to take action):
the __llvm_profile_keep references a bunch of stub data variables that are necessary to allow the linker to define the __stop___llvm_prf_vnds and other start/stop symbols, which are live because they are referenced by parts of the runtime that compute the filename. The start/stop symbols are weak declarations, but on AIX an undefined WEAK is an error (just like a regular undefined), so we need those stub data variables and stop the linker from GC'ing them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the usecase of defining __llvm_profile_runtime in the user code to avoid automatic initialization of the runtime, under the -bcdtors:mbr settings, is broken and users would need to create a reference to __llvm_profile_keep. We can add -u__llvm_profile_keep to the AIX link step in the driver, but I'm not sure if it will have some unintended consequences such as keeping any constructors defined in the same file as __llvm_profile_keep (none today). I'm in favor of keeping things as is, until we find the need to fix this.

#ifdef _AIX
extern __attribute__((visibility("hidden"))) void *__llvm_profile_keep[];
(void)*(void *volatile *)__llvm_profile_keep;
#endif // _AIX
}
#endif // PROFILE_TEST_H