Skip to content

feat: support the DEFINED command in linker scripts#2181

Open
vishruth-thimmaiah wants to merge 2 commits into
wild-linker:mainfrom
vishruth-thimmaiah:defined_cmd
Open

feat: support the DEFINED command in linker scripts#2181
vishruth-thimmaiah wants to merge 2 commits into
wild-linker:mainfrom
vishruth-thimmaiah:defined_cmd

Conversation

@vishruth-thimmaiah

@vishruth-thimmaiah vishruth-thimmaiah commented Jul 6, 2026

Copy link
Copy Markdown
Member

This PR adds support for the DEFINED command in linker scripts, which is used to check if a symbol has been declared or not.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
}
}
Expression::Defined(name) => Ok(symbol_db
.get_unversioned(&UnversionedSymbolName::prehashed(name))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure that this will do the correct thing if there are objects that reference, but don't define the symbol. Can you add a test for that? i.e. have an object that has a weak reference to the symbol.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
void _start() {}

int symbol4 = 0x4000;
int symbol6 __attribute__((weak));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that declaring a variable doesn't create a reference to it - you need to actually have some code that uses the variable for it to end up in the symbol table.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can verify this by running readelf -Ws on the object file to see what undefined symbols are listed.

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