Skip to content

Macro to generate ELF newtypes and new SymbolType#1228

Merged
davidlattimore merged 1 commit into
wild-linker:mainfrom
daniel-levin:main
Oct 19, 2025
Merged

Macro to generate ELF newtypes and new SymbolType#1228
davidlattimore merged 1 commit into
wild-linker:mainfrom
daniel-levin:main

Conversation

@daniel-levin

Copy link
Copy Markdown
Contributor

The code in linker-utils/src/elf.rs wraps enum constants from object in newtypes. It's got hand-written and sometimes missing implementations of Debug and Display for each. I introduced a macro to generate the newtype as well as a sub-module that contains the constants of this form:

pub const GNU_LIBLIST: SectionType = SectionType(object::elf::SHT_GNU_LIBLIST);

This has a few benefits. There is less hand-written code to maintain. Human error in naming the constants is no longer possible. The macro also generates common inherent methods and trait implementations for all the newtypes. The other nice thing is that there are now far fewer results when searching for values of these enums. Also, it's possible to define constants not present in object, such as RISCV_ATTRIBUTES.

I used this new macro to introduce another newtype - SymbolType. I've shoehorned in a couple of Debug derivations which originally catalyzed this work. There are fewer opaque integers in debug output. Example:

InternalSymDefInfo {
    placement: SectionEnd(
        osid-34,
    ),
    name: "_TLS_MODULE_BASE_",
    elf_symbol_type: TLS,
},

One new dependency is required - paste - but it is lightweight, compile-time only dtolnayware that was already in the dependency closure.

@davidlattimore davidlattimore merged commit 690e56a into wild-linker:main Oct 19, 2025
20 checks passed
davidlattimore added a commit that referenced this pull request Oct 20, 2025
PR #1228 changed how segment names get formatted.
davidlattimore added a commit that referenced this pull request Oct 20, 2025
PR #1228 changed how segment names get formatted. This PR adjusts some default
ignore rules in linker-diff to accomodate these changes.

We also change the macros added in #1228 so that to_str works for
RISCV_ATTRIBUTES.
davidlattimore added a commit that referenced this pull request Oct 20, 2025
PR #1228 changed how segment names get formatted. This PR adjusts some default
ignore rules in linker-diff to accomodate these changes.

We also change the macros added in #1228 so that to_str works for
RISCV_ATTRIBUTES.
davidlattimore added a commit that referenced this pull request Oct 20, 2025
PR #1228 changed how segment names get formatted. This PR adjusts some default
ignore rules in linker-diff to accommodate these changes.

We also change the macros added in #1228 so that to_str works for
RISCV_ATTRIBUTES.
daniel-levin pushed a commit to daniel-levin/wild that referenced this pull request Oct 23, 2025
PR wild-linker#1228 changed how segment names get formatted. This PR adjusts some default
ignore rules in linker-diff to accommodate these changes.

We also change the macros added in wild-linker#1228 so that to_str works for
RISCV_ATTRIBUTES.
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