Skip to content
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

--trace-symbol flag affects .symver #1168

Closed
brandonfoong opened this issue Dec 21, 2023 · 2 comments
Closed

--trace-symbol flag affects .symver #1168

brandonfoong opened this issue Dec 21, 2023 · 2 comments

Comments

@brandonfoong
Copy link

brandonfoong commented Dec 21, 2023

Using the following program,

#include <pthread.h>
#include <stddef.h>

__asm__(".symver pthread_join,pthread_join@GLIBC_2.2.5");

void* my_thread_start(void*) { return NULL; }

int main() {
    pthread_t my_thread;
    pthread_create(&my_thread, NULL, &my_thread_start, NULL);
    pthread_join(my_thread, NULL);
    return 0;
}

If I compile with -fuse-ld=mold and use nm -D to display the dynamic imports, I get

                 U __cxa_finalize@GLIBC_2.2.5
                 U __libc_start_main@GLIBC_2.34
                 U pthread_create@GLIBC_2.34
                 U pthread_join@GLIBC_2.2.5
                 U __stack_chk_fail@GLIBC_2.4

as expected.

However, if I add -Wl,-y,pthread_join@GLIBC_2.2.5, nm -D shows

                 U __cxa_finalize@GLIBC_2.2.5
                 U __libc_start_main@GLIBC_2.34
                 U pthread_create@GLIBC_2.34
                 U pthread_join@GLIBC_2.2.5@GLIBC_2.2.5
                 U __stack_chk_fail@GLIBC_2.4

Strangely, I could only get this to occur in Ubuntu 22.04, but not 20.04, which may be caused by glibc introducing a new default version to pthread_join.

@brandonfoong
Copy link
Author

It may be caused by this line adding foo@VER -> foo@VER into the symbol map

mold/elf/main.cc

Lines 382 to 383 in 0702d41

for (std::string_view arg : ctx.arg.trace_symbol)
get_symbol(ctx, arg)->is_traced = true;

when we actually want versioned symbols to map foo@VER -> foo

mold/elf/input-files.cc

Lines 1327 to 1329 in 0702d41

std::string_view mangled_name = save_string(
ctx, std::string(name) + "@" + std::string(version_strings[ver]));
this->symbols.push_back(get_symbol(ctx, mangled_name, name));

@rui314 rui314 closed this as completed in 35516a6 Dec 23, 2023
@rui314
Copy link
Owner

rui314 commented Dec 23, 2023

Thank you for your report! The above change should fix the issue.

VitalyAnkh pushed a commit to VitalyAnkh/mold that referenced this issue Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants