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

Should --clear-symbol-version remove versions from multiple instances? #252

Open
nitz opened this issue Nov 18, 2020 · 7 comments
Open

Should --clear-symbol-version remove versions from multiple instances? #252

nitz opened this issue Nov 18, 2020 · 7 comments
Labels

Comments

@nitz
Copy link

nitz commented Nov 18, 2020

Describe the bug

I have a shared object I'm attempting to remove the symbol version from that is linking to a newer version of libm.so than my machine has. The shared object seems to have 2 instances of the symbol, one in .dynsym the other in .symtab, but the --clear-symbol-version flag only seems to work on the first.

Steps To Reproduce

Example:

cmd@t:~/app $ readelf -a libMySharedObject.so | grep pow
000b3000  00007416 R_ARM_JUMP_SLOT   00000000   pow@GLIBC_2.29
   116: 00000000     0 FUNC    GLOBAL DEFAULT  UND pow@GLIBC_2.29 (15)
  6483: 00000000     0 FUNC    GLOBAL DEFAULT  UND pow@@GLIBC_2.29

cmd@t:~/app $ patchelf --clear-symbol-version pow libMySharedObject.so --debug
patching ELF file 'libMySharedObject.so'
clearing symbol version for pow
writing libMySharedObject.so

cmd@t:~/app $ readelf -a libMySharedObject.so | grep pow
000b3000  00007416 R_ARM_JUMP_SLOT   00000000   pow
   116: 00000000     0 FUNC    GLOBAL DEFAULT  UND pow
  6483: 00000000     0 FUNC    GLOBAL DEFAULT  UND pow@@GLIBC_2.29

cmd@t:~/app $

Expected behavior

Both symbols should have their version requirement removed, not just the first. Is it perhaps because the second symbol is in .symtab? The one that survives, pow@@GLIBC_2.29 still shows up with, and still seems to be required:

cmd@t:~/app $ ./test
./test: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.29' not found (required by ./libMySharedObject.so)

patchelf --version output

patchelf 0.12

Additional context

The binary is a cross compiled binary (host machine was x86_64, target is armv8a.
I unfortunately don't have a binary I can share at this time, but may be able to do so in the future.

@nitz nitz added the bug label Nov 18, 2020
@nitz
Copy link
Author

nitz commented Nov 19, 2020

I had a few moments to dig into the source, and it does look like it's not checking the .symtab section. I thought to add it myself, but I only have a cursory knowledge of ELF in general, and am not sure where the .symtab section stores it's symbol versions. (I'm guessing not .gnu.version, since the size of .gnu.version seems required to match the size of .dynsym?)

@Radvendii
Copy link

Radvendii commented Mar 21, 2021

I'm also having this problem. Did you find a solution / workaround?

@nitz
Copy link
Author

nitz commented Mar 21, 2021

I never did. I ended up just building that one particular library on a target set up like my actual target. Not really a great workaround but was enough to let me move forward.

@Radvendii
Copy link

Ah, bummer. I'm not sure what the use-case for --clear-symbol-version is that works, given that it's also not documented in the man page (#258). But anyways, I'm exploring other options now. This is kind of an error-prone hack anyways for what we were trying to do.

@nitz
Copy link
Author

nitz commented Apr 15, 2021

This is kind of an error-prone hack anyways for what we were trying to do.

Mayyyybe ;) I'm still convinced it probably would have worked if I knew better how to get the other symbol references out. 🤷🏻‍♀️

@Radvendii
Copy link

Oh it might have worked for your use-case, if you just wanted a particular binary to work on a particular computer. But it's not very robust; if there's a breaking change to the symbol's ABI, the program wouldn't know to use the right version, and would break on updated computers. That's the whole reason for symbol versioning, no?

Anyways, I managed to make an overlay that uses an older version of GLIBC, so that worked. =)

@z16166
Copy link

z16166 commented Feb 20, 2023

1, ".dynsym" is for loader/linker.
2, ".symtab" is for debugger, which can be erased by "strip" command.

so patchelf can be used to deal with glibc symbol version of stripped elf files.

chitao1234 added a commit to chitao1234/patchelf that referenced this issue Aug 2, 2024
Should fix NixOS#252, NixOS#284, --remove-needed-version works by removing
specified version in .gnu.version_r, and resets version in referenced
entry in .gnu.version.
chitao1234 added a commit to chitao1234/patchelf that referenced this issue Aug 3, 2024
Should fix NixOS#252, NixOS#284, --remove-needed-version works by removing
specified version in .gnu.version_r, and resets version in referenced
entry in .gnu.version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants