Skip to content

Conversation

@katsyoshi
Copy link
Owner

@katsyoshi katsyoshi commented Jan 11, 2026

Summary

  • add linker symbol resolution pass that rejects duplicate globals
  • expose symtab entry info and use it for binding checks
  • wire linker builder into self-linking flow

Testing

  • ruby test/caotral/compiler_test.rb

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a145bf1f50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@katsyoshi katsyoshi force-pushed the adjust-symtab-section-header branch from 2cd8a69 to 3a54b40 Compare January 13, 2026 11:49
@katsyoshi
Copy link
Owner Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a54b40262

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +86 to +89
name, info, link, entsize = (name_offset.nil? ? 0 : name_offset), header.info, header.link, 0
if header.type == :symtab
info = section.body.size
link = strtabndx

Choose a reason for hiding this comment

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

P2 Badge Set symtab sh_info to local symbol count

In ELF, a symtab section’s sh_info must be the index of the first non-local symbol (i.e., the count of local symbols). Here info = section.body.size sets it to the total symbol count, so any global symbols are effectively marked as local to consumers that rely on sh_info. This shows up whenever the input has globals (e.g., the main symbol from the assembler or GCC-produced objects), and it can cause tools/linkers to misclassify or ignore globals.

Useful? React with 👍 / 👎.

Comment on lines +110 to +114
write_order << @elf_obj.find_by_name(".text")
write_order << @elf_obj.find_by_name(".symtab")
write_order << @elf_obj.find_by_name(".strtab")
write_order.concat(@elf_obj.select_by_names([/\.rel\./, /\.rela\./]))
write_order << @elf_obj.find_by_name(".shstrtab")

Choose a reason for hiding this comment

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

P2 Badge Avoid emitting rel sections without target sections

The write order now includes every .rel.*/.rela.* section but only keeps .text, .symtab, .strtab, and .shstrtab. For objects that also have relocations for other sections (e.g., GCC adds .rela.eh_frame alongside .eh_frame), this emits relocation sections whose referenced target section is omitted from the output. That leaves sh_info pointing at a section index that doesn’t exist in the new section table, producing an invalid ELF that can confuse tooling. Either include the referenced sections or drop relocations whose targets aren’t being written.

Useful? React with 👍 / 👎.

@katsyoshi katsyoshi merged commit 8ba9a55 into main Jan 13, 2026
2 checks passed
@katsyoshi katsyoshi deleted the adjust-symtab-section-header branch January 13, 2026 12:04
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