Normalising linker command lines #655
davidlattimore
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Originally posted by @lu-zero in #527 (comment)
Let's continue discussion on a separate thread.
Interesting. That sounds tricky. Order can certainly be important. With linkers like GNU ld, almost any change to order could potentially cause the link to fail, especially if archives are used. With GNU ld, an object within an archive is only loaded if it defines at least one symbol that was, at that point in the command-line, undefined. So moving an archive earlier in the command-line could cause one or more of the objects within the archive to not get used, which could result in undefined symbols, or worse, changes in runtime behaviour. The other linkers - LLD, Mold and Wild are less sensitive to order of archives, allowing archives earlier in the command-line order to be triggered by undefined symbols later in the command-line.
Beyond archives, there's weak symbols, which can have multiple definitions. Ideally all definitions would be the same, but it isn't necessarily the case.
There's also flags that affect the way subsequent objects get treated, but which don't affect earlier objects. Then there are flags like
--push-state
and--pop-state
that manipulate a stack of states.With some other flags. e.g. things like
--gc-sections
can appear anywhere in the command-line without changing the behaviour - with the caveat, that if there's also a--no-gc-sections
, then whichever is later will take precedence.I guess a conservative approach to normalising linker command-lines might be to have specific rules that make particular kinds of changes to eliminate the kinds of redundancy or denormalisation that you expect to see. For example for flags that you know the order doesn't matter for, move them all to one end and remove any earlier negations or repeated copies of that flag.
Beta Was this translation helpful? Give feedback.
All reactions