Skip to content

Conversation

@katsyoshi
Copy link
Owner

@katsyoshi katsyoshi commented Feb 8, 2026

Summary

  • Add .data section support for PIE output and fold relocations into .rela.dyn
  • Populate dynamic tags (HASH/STRTAB/SYMTAB/STRSZ/SYMENT/TEXTREL) and add .hash
  • Fix PT_PHDR/PT_LOAD layout for PIE (base=0 assumption)
  • Add movabs sample and a PIE execution test

Testing

  • rake test

Notes

  • PT_LOAD is currently RWE (minimal implementation); RW/RX split can be done later

@katsyoshi katsyoshi changed the title Support pie PIE: data section + dynamic tags + PHDR layout Feb 8, 2026
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: 8c3fd035a3

ℹ️ 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 +18 to 21
def link(inputs: @inputs, output: @output, debug: @debug, shared: @shared, executable: @executable, pie: @pie)
return to_elf(inputs:, output:, debug:, shared:, executable:, pie:) if @linker == "self"

IO.popen(link_command).close

Choose a reason for hiding this comment

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

P1 Badge Honor pie flag for non-self linkers

When linker is not "self" (the default path), the pie flag is ignored and the code just runs link_command without adding a -pie/--pie option. This means callers using Linker.link!(..., pie: true, linker: "mold") still get a non-PIE executable, which defeats the new feature outside the self-linker path. The issue is triggered whenever pie: true is combined with a non-self linker.

Useful? React with 👍 / 👎.

Comment on lines +368 to +370
body: [
Caotral::Binary::ELF::Section::Dynamic.new.set!(tag: tag_types[:HASH], un: 0),
Caotral::Binary::ELF::Section::Dynamic.new.set!(tag: tag_types[:RELA], un: 0),

Choose a reason for hiding this comment

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

P2 Badge Avoid emitting DT_HASH without a .hash section

The dynamic section now unconditionally adds a DT_HASH entry, but .hash is only emitted for PIE (sections << build_hash_section if @pie). For shared objects (shared: true, pie: false), DT_HASH remains zero because the writer only fills it when hash_section exists. A DT_HASH tag with a null pointer is invalid and can cause the dynamic loader to reject or mis-handle the shared object. Either add .hash for shared builds as well, or only emit DT_HASH when the section exists.

Useful? React with 👍 / 👎.

@katsyoshi katsyoshi merged commit 5069054 into main Feb 11, 2026
2 checks passed
@katsyoshi katsyoshi deleted the support-pie-dyn-and-interp branch February 11, 2026 00:38
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.

1 participant