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

Why is the dynamic linker explicitly overridden? #3

Open
gilice opened this issue Apr 5, 2024 · 3 comments
Open

Why is the dynamic linker explicitly overridden? #3

gilice opened this issue Apr 5, 2024 · 3 comments

Comments

@gilice
Copy link

gilice commented Apr 5, 2024

wrecc/src/main.rs

Lines 152 to 153 in 37a8413

.arg("-dynamic-linker")
.arg("/lib64/ld-linux-x86-64.so.2")

This explicitly sets the dynamic linker to a fixed value.
This could fail in a few ways:

  • the system only has /lib64/ld-linux-x86-64.so.1 (unlikely)
  • the system doesn't have /lib64/ld-linux-x86-64.so.2 -> like NixOS (which is a linux distribution!), and of course BSDs (if you want to support them in the future).

I did a few tests and it looks like LD has its own logic for resolving a dynamic linker.

man 1 ld also warns against setting your own dynamic linker, saying "The default dynamic linker is normally correct".

By removing these lines, the executables generated by wrecc could run unpatched on NixOS.

@PhilippRados
Copy link
Owner

PhilippRados commented Apr 5, 2024

Yes, I just tried omitting those lines on my VM but then I get the error:

bash: ./a.out: No such file or directory

which from a quick google search happens from wrong linking.
I checked how gcc invokes the linker with gcc -v file.o and it also uses the -dynamic-linker option.
Either it doesn't work using the default linker or it doesn't even find it.
If you have an idea what option to pass to properly invoke the default dynamic linker then I'm all here for it, but it seems that the default dynamic linker doesn't work on my machine.
Or you could tell me where on NixOs the *.so.2 file is located so I can also add a default search-path to be iterated over to be used as an argument for the -dynamic-linker option.

@gilice
Copy link
Author

gilice commented Apr 5, 2024

Okay, so if I understand correctly, it doesn't work on your machine without explicitly passing --dynamic-linker?
Sad.

Or you could tell me where on NixOs the *.so.2 file is located so I can also add a default search-path to be iterated over to be used as an argument for the -dynamic-linker option.

There is not such a place, sorry. NixOS does a lot of weird tricks (like not having a standard dynamic linker) for reproducibility reasons.

I guess then it's best just to either

  • ignore the issue => NixOS is not a very popular distribution, and those who use it can solve the issue themselves
  • add a compiler flag for setting the dynamic-linker option
    • in gcc this would be gcc -Xlinker -dynamic-linker my-custom-dynamic-linker

Thanks for your quick reply.


Just for the sake of curiosity: what does readelf -a a.out | grep interpreter say for the a.out file that you are unable to run?

@PhilippRados
Copy link
Owner

PhilippRados commented Apr 5, 2024

$ readelf -a a.out | grep interpreter
[Requesting program interpreter: /lib/ld64.so.1]

It seems like thats the default linker which doesn't work.

Yes I might add an -Xlinker flag in the future which could be quite helpful for this sort of stuff.

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