This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Implemented --defsym option
AbandonedPublic

Authored by grimar on Apr 14 2017, 7:11 AM.

Details

Reviewers
ruiu
rafael
Summary

gnu ld description of option is:

--defsym=symbol=expression
Create a global symbol in the output file, containing the absolute address given by expression. You may use this option as many times as necessary to define multiple symbols in the command line. A limited form of arithmetic is supported for the expression in this context: you may give a hexadecimal constant or the name of an existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or symbols. If you need more elaborate expressions, consider using the linker command language from a script. Note: there should be no white space between symbol, the equals sign ("="), and expression.

Patch implements support for option using existent expression evaluator we have for linkerscript.
So that means this patch supports full math in --defsym expressions.

This fixes PR32350

Diff Detail

Event Timeline

grimar created this revision.Apr 14 2017, 7:11 AM
grimar updated this revision to Diff 95295.Apr 14 2017, 7:19 AM
  • Removed useless change.
ruiu edited edge metadata.Apr 14 2017, 9:29 AM

This doesn't look good as you changed too many places for this little feature. Do you really have to support expressions that contain operators? I think you can start with supporting an assignments that consist of only two symbols in the form of -defsym=<sym1>=<sym2>.

In D32082#727317, @ruiu wrote:

This doesn't look good as you changed too many places for this little feature. Do you really have to support expressions that contain operators? I think you can start with supporting an assignments that consist of only two symbols in the form of -defsym=<sym1>=<sym2>.

Ok, I just was interested if our linkerscript parsing code can be easily adopted to use for this option. I read your comment in PR32350, you wrote it's "tricky", I was interested "how much" :)
So if it is too much I'll prepare separate patch for simpler cases (1 and/or 3 from your comment).

grimar abandoned this revision.Apr 25 2017, 3:50 AM

D32171 is on review instead