This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Update st_size when merging a common symbol with a shared symbol
ClosedPublic

Authored by MaskRay on Dec 6 2019, 10:42 PM.

Details

Summary

When a common symbol is merged with a shared symbol, increase st_size if
the shared symbol has a larger st_size. At runtime, the executable's
symbol overrides the shared symbol. The shared symbol may be created
from common symbols in a previous link. This rule makes sure we pick
the largest size among all common symbols.

This behavior matches GNU ld. See
https://sourceware.org/bugzilla/show_bug.cgi?id=25236 for discussions.

A shared symbol does not hold alignment constraints. Ignore the
alignment update.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 6 2019, 10:42 PM

Reading through the PR I think that this is the right thing to. I think that there is a possibility of narrowing down the assumption that a Shared definition is common, by checking its address against the loadable segment containing BSS. I don't think it is worth doing that.

peter.smith accepted this revision.Dec 13 2019, 12:24 AM

Looks good to me. Will be worth seeing if there are any comments in the US time zone.

This revision is now accepted and ready to land.Dec 13 2019, 12:24 AM
ruiu added a comment.Dec 13 2019, 12:33 AM

This behavior seems to make sense but is very subtle. Can you add a comment to explain what this is doing?

MaskRay updated this revision to Diff 233743.Dec 13 2019, 12:42 AM

Add comments

This revision was automatically updated to reflect the committed changes.