Skip to content

Conversation

nsavoire
Copy link

@nsavoire nsavoire commented May 16, 2025

Symbolic currently relies on DYNAMIC segment to locate and parse dynamic symbols.
This works for full executables but not for debug information extracted with objcopy --only-keep-debug where we have added back dynamic symbol sections (.dynsym / .dynstr), because in those files, DYNAMIC segment is stripped.
This PR adds the ability to use section headers to locate .dynsym and .dynstr sections when DYNAMIC segment cannot be used.

@nsavoire nsavoire marked this pull request as ready for review May 16, 2025 15:43
@nsavoire nsavoire changed the title Add support for dynamic symbols when DYNAMIC program header is absent Add support for dynamic symbols when DYNAMIC segment is mising May 21, 2025
@nsavoire nsavoire changed the title Add support for dynamic symbols when DYNAMIC segment is mising Add support for dynamic symbols when DYNAMIC segment is missing May 21, 2025
@buranmert buranmert requested a review from Copilot May 21, 2025 15:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables parsing of dynamic symbols and their string table from section headers when the PT_DYNAMIC segment is absent, falling back to PT_DYNAMIC only if needed.

  • Initialize dynsyms and dynstrtab earlier to a known default state
  • Add parsing of .dynsym/.dynstr via SHT_DYNSYM section
  • Introduce fallback logic: use DYNAMIC segment only if section-based tables are empty
Comments suppressed due to low confidence (1)

symbolic-debuginfo/src/elf.rs:245

  • Add unit tests to verify the new fallback behavior: parsing .dynsym/.dynstr sections in the absence of a PT_DYNAMIC segment, ensuring correct symbol resolution for debug-only ELF files.
if obj.dynstrtab.len() == 0 {

If dynamic symbols cannot be parsed from the DYNAMIC segment, try to
parse them from the section headers.
@nsavoire
Copy link
Author

Some open questions:

  • How should we name this new version ? Should we use a new branch ? (Since the current version is identified by this branch, not a tag)
  • Should we also update to a newer symbolic version? (I noticed this change that could be interesting)

@nsavoire nsavoire requested a review from Copilot May 22, 2025 07:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a fallback mechanism to locate and parse dynamic symbols using section headers when the DYNAMIC segment is missing, targeting debug information files produced by objcopy.

  • Added fallback logic in elf.rs to iterate over section headers and parse .dynsym and .dynstr sections when obj.dynsyms is empty
  • Adjusted data parsing to support files without a DYNAMIC segment

ctx
));

obj.dynstrtab = return_partial_on_err!(get_strtab(&obj.section_headers, shdr.sh_link as usize));
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After successfully parsing the dynamic symbol table and string table, consider breaking out of the loop to prevent potential overwrites if multiple SHT_DYNSYM sections are present.

Suggested change
obj.dynstrtab = return_partial_on_err!(get_strtab(&obj.section_headers, shdr.sh_link as usize));
obj.dynstrtab = return_partial_on_err!(get_strtab(&obj.section_headers, shdr.sh_link as usize));
break;

Copilot uses AI. Check for mistakes.

@nsavoire nsavoire force-pushed the nsavoire/dynsym branch 3 times, most recently from 486baf3 to 00204c9 Compare June 23, 2025 15:11
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.

2 participants