Skip to content

[sanitizer_common][AIX] Avoid weak symbol __cxa_demangle #138556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,36 @@
// because we do not require a C++ ABI library to be linked to a program
// using sanitizers; if it's not present, we'll just use the mangled name.
namespace __cxxabiv1 {
# if !SANITIZER_AIX
extern "C" SANITIZER_WEAK_ATTRIBUTE char *__cxa_demangle(const char *mangled,
char *buffer,
size_t *length,
int *status);
# else
// `weak` attribute without definition on AIX will cause linking time undefined
// symbol error, we use dlopen/dlsym here to find related symbol.
typedef char *__cxa_demangle_t(const char *mangled, char *buffer,
size_t *length, int *status);

char *__cxa_demangle(const char *mangled, char *buffer, size_t *length,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The sanitizer should not define a __cxa_demangle that could satisfy a link dependency from the user program.

int *status) {
// Use NULL as the module name, so if the libc++abi module is linked into the
// main executable, we are able to find the __cxa_demangle symbol and this
// impelemtation will not force libc++abi to be loaded to the executable.
void *Handler = dlopen(0, RTLD_NOW);
if (!Handler) {
return nullptr;
}

auto FooPtr =
reinterpret_cast<__cxa_demangle_t *>(dlsym(Handler, "__cxa_demangle"));
if (!FooPtr) {
return nullptr;
}

return FooPtr(mangled, buffer, length, status);
}
# endif
}

namespace __sanitizer {
Expand Down
Loading