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

After removing DT_NEEDED, clean STRTAB. #449

Open
r-hoogenboom opened this issue Dec 14, 2022 · 2 comments
Open

After removing DT_NEEDED, clean STRTAB. #449

r-hoogenboom opened this issue Dec 14, 2022 · 2 comments

Comments

@r-hoogenboom
Copy link

After removing a DT_NEEDED with --remove-needed, the removed string still appears in STRTAB, only the reference is removed in the dynamic section.

It would be nice to add an option --clean-strtab that can be used to remove all unreferenced (orphan) strings from STRTAB. I know this is not trivial, because all references to STRTAB have to be rewritten...
Maybe print the removed strings from STRTAB when using --verbose too.

@ghost
Copy link

ghost commented Jan 12, 2023

Possibly same root cause:

@r-hoogenboom
Copy link
Author

Yes, it seems the issue #453 is the same root cause: only the .dynamic is changed to remove the reference to the string, but it still leaves the orphaned string in .dynstr. My suggested cleanup of .dynstr will also solve that.
I have been looking into how to clean up the .dynstr, removing all unreferenced strings, but my C++ skills are not so great. There are quite a few sections that can refer strings in .dynstr. After removing the unreferenced string(s), all offsets that refer to strings after the removed one(s) have to be updated and then the .dynstr can be shrunk. I wonder if after shrinking .dynstr, I probably need to call 'rewrite_sections', right?
Once I have it working, I can make a pull request and you can convert some C code into more C++, agree @amjoseph-nixpkgs ?

I was thinking that .dynstr could also be 'optimized' by sharing strings like 'vsprintf' with 'sprintf' and 'printf', but apparently the GNU linker already does that! This also means that for refcounting, not only the beginning of a string in .strtab should be considered, but the whole range of the string.

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

1 participant