This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support --defsym option to define an absolute symbol.
ClosedPublic

Authored by ruiu on Mar 27 2014, 6:40 PM.

Details

Summary

This patch is to support --defsym option for ELF file format/GNU-compatible
driver. Currently it takes a symbol name followed by '=' and a number. If such
option is given, the driver sets up an absolute symbol with the specified
address. You can specify multiple --defsym options to define multiple symbols.

GNU LD's --defsym provides many more features. For example, it allows users to
specify another symbol name instead of a number to define a symbol alias, or it
even allows a symbol plus an offset (e.g. --defsym=foo+3) to define symbol-
relative alias. This patch does not support that, but will be supported in
subsequent patches.

Diff Detail

Event Timeline

shankarke requested changes to this revision.Mar 28 2014, 6:06 AM

I am not sure if you have seen this thread on lld --defsym option, it's more complicated than this to implement to reflect behavior like gnu ld.

Note : the symbol gets defined in the output file only if there is a relocation to it or a reference to it. Any global symbol should still override defsym option.

http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-August/065094.html

My bad, the symbol gets defined no matter what, but the symbol thats created(should not be an absolute atom, but a defined atom) needs to have content, the content is set to the expression.

The thread should have more information on the overall design for supporting --defsym with the Gnu flavor.

ruiu added a comment.Mar 28 2014, 9:24 AM

That is out of scope of this patch. Let's don't combine everything into
one. --defsym=<symbol>=<immediate> is different kind of beast than
--defsym=<symbol>=<symbol>[+more expressions] although they share the same
option, and this patch is sufficient for the former. We need to address the
latter, and we can continue discussing, but that topic is separated from
this thread.

shankarke accepted this revision.Mar 28 2014, 9:42 AM

Ok, I agree about that its more complex to have the complete --defsym option.

Once the above comment is fixed, this patch LGTM.

lib/Core/LinkingContext.cpp
59–61 ↗(On Diff #8189)

Can we use a separate string for -u and --defsym. We could have a createCommandLineFile with a StringRef like how PECOFF does, so that we can support more command line defined by various options.

ruiu closed this revision.Mar 28 2014, 12:09 PM

Closed by commit rL205029 (authored by @ruiu).