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

write/elf: fix writing of strtab when symtab is empty #710

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

philipc
Copy link
Contributor

@philipc philipc commented Jul 23, 2024

Previously, if the symtab was empty then we were writing a strtab that had 0 bytes of data. This gives a linker error:
SHT_STRTAB string table section [index 4] is empty

Also, if there is a symtab then there must be a strtab, otherwise the error is:
invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL

Closes #709

@klensy
Copy link

klensy commented Jul 23, 2024

= note: rust-lld: error: /home/user/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-0a0cf8f8a42e5845.rlib(lib.rmeta): invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
          collect2: error: ld returned 1 exit status

@philipc
Copy link
Contributor Author

philipc commented Jul 23, 2024

@klensy I've force pushed a new attempt to fix this.

@klensy
Copy link

klensy commented Jul 23, 2024

This works (but it will be nice to actually find why it failed before, is it ld requirement?).

@philipc
Copy link
Contributor Author

philipc commented Jul 23, 2024

An empty strtab is always invalid, so that part is a bug in this crate, and ld rightly complained about it.

In theory it should be able to work without a strtab if there are no strings, but I haven't checked what the ELF spec says for that and my first attempt showed ld didn't support that either. A missing dynstr is valid, which is what #646 was fixing, but it incorrectly changed the strtab handling too.

The current fix in this PR is still a bit of a hack. Now that I know what's needed, I'll do a better fix and some testing tomorrow.

@philipc philipc changed the title write/elf: don't write empty strtab write/elf: fix writing of strtab when symtab is empty Jul 24, 2024
Previously, if the symtab was empty then we were writing a strtab
that had 0 bytes of data. This gives a linker error:
SHT_STRTAB string table section [index 4] is empty

Also, if there is a symtab then there must be a strtab,
otherwise the error is:
invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
@philipc philipc marked this pull request as ready for review July 24, 2024 02:30
@philipc philipc merged commit 3a396f3 into gimli-rs:master Jul 24, 2024
10 checks passed
@philipc philipc deleted the issue-709 branch July 24, 2024 02:42
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

Successfully merging this pull request may close these issues.

rustc fails to build with object 0.35+
2 participants