Emit correct ELF symbol types for data in NativeAOT objects#129950
Merged
Conversation
ElfObjectWriter classified defined symbols solely by size (Size > 0 ? STT_FUNC : STT_NOTYPE). This had two problems: - Data symbols pointing at a non-zero offset within their node (e.g. MethodTable/EEType vtables, which sit after the GCDesc) get Size == 0, so they were emitted as STT_NOTYPE. Released lldb only infers a type for NOTYPE symbols in a hard-coded set of section names (.text/.data/.rodata/.bss); symbols in other allocated sections such as .hydrated stay untyped and are not surfaced in symbol lookup. - Data symbols with Size > 0 in .rodata/.data were emitted as STT_FUNC, i.e. data mislabeled as code. Classify by section instead: non-executable sections emit STT_OBJECT, executable sections keep the existing STT_FUNC/STT_NOTYPE behavior. This is the canonical typing other ELF producers use, helps every consumer that reads st_info directly (lldb, gdb, nm, addr2line, perf), and is size-neutral. Executable-section symbols are unchanged, so ARM/AArch64/RISC-V mapping symbols and trampolines are unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates NativeAOT’s ELF object writer symbol-table emission to choose ELF symbol types based on section flags (TLS / executable vs non-executable), rather than inferring type from symbol size alone.
Changes:
- Adjust symbol classification in
ElfObjectWriter.EmitSymbolTableto emitSTT_OBJECTfor defined symbols in non-executable sections. - Preserve existing
STT_FUNC/STT_NOTYPEbehavior for executable sections and keepSTT_TLSfor TLS sections.
jkotas
approved these changes
Jun 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ElfObjectWriter.EmitSymbolTableclassified every defined symbol purely by size:This produced two wrong results for data symbols:
STT_NOTYPE. AMethodTable/EEType symbol points at a non-zero offset within its node (the EEType sits after the GCDesc), soSize == 0and it becameSTT_NOTYPE. Released lldb only infers a type forNOTYPEsymbols whose section name is in a hard-coded list (.text/.data/.rodata/.bss); symbols in other allocated sections such as.hydrated(the NOBITS region that rehydrated data structures live in when data dehydration is enabled) stay untyped and are not surfaced in lldb symbol lookup. Tools that readst_infodirectly (gdb,nm,addr2line,perf) never see a type at all.STT_FUNC. Data symbols withSize > 0in.rodata/.datawere markedSTT_FUNC, i.e. data mislabeled as code (lldb then treats them as functions).Fix
Classify by section kind instead of size:
Non-executable sections emit
STT_OBJECT; executable sections keep the existingSTT_FUNC/STT_NOTYPEbehavior unchanged. This matches the canonical typing every other ELF producer uses and is size-neutral (only thest_infotype byte changes).Validation
Cross-emitted a Linux x64 object (
--targetos:linux, dehydration on) before/after the change from an otherwise identical toolchain. Object size is byte-identical (3,555,456 bytes)..hydrated(NOBITS, vtables)NOTYPE+ 377FUNCOBJECT.rodataFUNC(+2NOTYPE)OBJECT.dataFUNCOBJECT.text(code)FUNCFUNC(unchanged)Executable-section symbols are untouched, so ARM/AArch64/RISC-V mapping symbols (
$a/$d/$x) and trampolines are unaffected.Note
This PR description was generated with the assistance of GitHub Copilot.