Page MenuHomePhabricator

[LLD][ELF] Extract temporary state used in assignAddresses()
ClosedPublic

Authored by peter.smith on Jun 19 2017, 3:49 AM.

Details

Summary

The assignAddresses() function accumulates state in the LinkerScript that prevents it from being called multiple times. This change moves the state into a separate structure AddressState that is created at the start of the function and disposed of at the end.

CurAddressState is used rather than passing a reference to the state as a parameter to the functions used by assignAddresses(). This is because the getSymbolValue function needs to be executed in the context of AddressState but it is stored in ScriptParser when AddressState is not available.

The AddressState is also used in a limited context by processCommands()

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.Jun 19 2017, 3:49 AM

This is patch 4/11 of range thunks although it can be applied independently.

peter.smith retitled this revision from [LLD][ELF] Reset any accumulated state before calculating addresses to [LLD][ELF] Extract temporary state used in assignAddresses().
peter.smith edited the summary of this revision. (Show Details)

I've updated to follow Rafael's suggestion to extract the state into a separate struct. The diff is mostly a replace Cur<State> with CurAddressState-><State>.

This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.
lld/trunk/ELF/LinkerScript.cpp
377

Coverity flags this as suspicious (and I agree):

>>>     CID 1377401:  Memory - illegal accesses  (WRAPPER_ESCAPE)
>>>     The internal representation of local "State" escapes into "this->CurAddressState", but is destroyed when it exits scope.

If this is intended, please add a comment.

mehdi_amini added inline comments.Jul 10 2017, 4:21 PM
lld/trunk/ELF/LinkerScript.cpp
846

Same here actually