This is an archive of the discontinued LLVM Phabricator instance.

[lld] [ELF] Fix wrong TBSS size
ClosedPublic

Authored by zatrazz on Jun 16 2015, 10:41 AM.

Details

Summary

This patch fixes the wrong .tbss segment size generated for cases where
multiple modules have non initialized threads variables. For instance:

  • t0.c --

thread int x0;
thread int x1;
__thread int x2;

extern thread int e0;
extern
thread int e1;
extern thread int e2;
extern
thread int e3;

int foo0 ()
{

return x0;

}

int main ()
{

return x0;

}

  • t1.c --

thread int e0;
thread int e1;
thread int e2;
thread int e3;


lld is generating (for aarch64):

[14] .tbss             NOBITS           0000000000401000  00001000
     0000000000000010  0000000000000000 WAT       0     0     4

Where is just taking in consideration the largest tbss segment, not all
from all objects. ld generates a correct output:

[17] .tbss             NOBITS           0000000000410dec  00000dec
     000000000000001c  0000000000000000 WAT       0     0     4

This issue is at 'lib/ReaderWriter/ELF/SegmentChunks.cpp' where
Segment<ELFT>::assignVirtualAddress is setting wrong slice values, not taking care
of although tbss segments file size does noy play role in other segment virtual
address placement, its size should still be considered.

Diff Detail

Event Timeline

zatrazz updated this revision to Diff 27771.Jun 16 2015, 10:41 AM
zatrazz retitled this revision from to [lld] [ELF] Fix wrong TBSS size.
zatrazz updated this object.
zatrazz edited the test plan for this revision. (Show Details)
zatrazz added reviewers: ruiu, shankar.easwaran.
zatrazz added a project: lld.
zatrazz added subscribers: Unknown Object (MLST), lld.
ruiu accepted this revision.Jun 16 2015, 3:10 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 16 2015, 3:10 PM
shankar.easwaran edited edge metadata.

LGTM

zatrazz closed this revision.Jun 24 2015, 6:34 AM