This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not set st_size field of SHT_UNDEF symbols
ClosedPublic

Authored by grimar on Jun 27 2017, 2:04 AM.

Details

Summary

This fixes PR33598.

It looks may be usefult for next case:
When we have 2 DSO's, like in this PR, if lower level DSO may change slightly (in part of some symbol's st_size)
and higher-level DSO is rebuilt, then tools that monitoring checksum of high level DSO file can notice it and trigger
cascade of some other unnecessary actions. If we set st_size to zero, that can be avoided.

gABI says: "st_size
Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object.
This member holds 0 if the symbol has no size or an unknown size."
(http://refspecs.linuxbase.org/elf/gabi4+/ch4.symtab.html)

Looks setting zero is correct from gABI size because in the given example above symbol size can be different in runtime
and therefore can be probably called 'unknown' when linking.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Jun 27 2017, 2:04 AM
grimar updated this revision to Diff 104110.Jun 27 2017, 2:05 AM
  • Added forgotten input file.
phosek added a subscriber: phosek.Jun 27 2017, 8:12 AM
ruiu edited edge metadata.Jun 27 2017, 11:10 AM

LGTM with comment change.

ELF/SyntheticSections.cpp
1388–1392 ↗(On Diff #104110)

It seems this comment describes something too specific. The most important part is that the size field for the undefined symbol is not significant, so it can be any value. You didn't mention that. I'd write:

// Copy symbol size if it is a defined symbol. st_size is not significant for undefined symbols,
// so whether copying it or not is up to us if that's the case. We'll leave it as zero
// because by not setting a value, we can get the exact same outputs for two sets of input files that
// differ only in undefined symbol size in DSOs.
if (ESym->st_shndx != SHN_UNDEF)
  ESym->st_size = Body->getSize<ELFT>();
grimar added inline comments.Jun 28 2017, 2:47 AM
ELF/SyntheticSections.cpp
1388–1392 ↗(On Diff #104110)

Ok, thanks !

This revision was automatically updated to reflect the committed changes.