Commit Graph

4726 Commits

Author SHA1 Message Date
Pete Cooper 52db793d33 Improved debugging printing. NFC
llvm-svn: 256805
2016-01-05 01:56:59 +00:00
Pete Cooper 921227c3bc Fix test case comment after r256786. NFC.
The comment spacing was meant to show the interesting bytes in the prior
line, but the prior line moved slightly.

llvm-svn: 256800
2016-01-05 00:47:22 +00:00
Pete Cooper bd364ce694 Sort sections in relocatable files.
The final section order in relocatable files was just a side effect
of the atom sorter.  This meant that sections like __data were before
__text because __data has RW permissions and __text RX and RW was less
than RX in our enum.

Final linked images had an actual section/segment sorter.  There was no
reason for the difference, so simplify a bunch of code and just use the
same sorted for everything.

Reviewed by Lang Hames.

http://reviews.llvm.org/D15868

llvm-svn: 256786
2016-01-04 22:29:36 +00:00
Pete Cooper 9942bd025d Fix x86_64 delta*Anon relocs.
The encoded value should be an offset from the fixup location, which
means that it should take in to account the fixup offset in its section.

We weren't subtracting the base address of the atom, which meant that when
we parsed the file again for a round trip, we had 2x the atom address in our
target address.

I've also improved comments for these to try and describe what is going on.

There's no test case right now, as the bug is only exhibited when __data is at
a non-zero address in a -r link.  A commit will soon sort the sections differently
and move __data to after __text.  Then these relocations in
test/mach-o/parse-data-relocs-x86_64.yaml will test for this bug.

llvm-svn: 256779
2016-01-04 21:23:12 +00:00
George Rimar 147747ab0b Revert or r256638. I`ve lost a little piece of code when resolved conflicts right before commit. Sorry about that.
Test did not catch this either, so I`ll improve it and recommit later.

Original commit message:
[ELF] - Optimize .eh_frame section: remove CIE if all FDEs referencing it were removed.

This patch performs little optimization for eh_frame section.
If all FDE`s that referenced CIE are removed then CIE is also removed from output. 
That can happen for example when dropping FDEs that point to dropped sections. Testcase showing that is included.
The same optimization was added to ld about 14 years ago: https://sourceware.org/ml/binutils/2001-12/msg00144.html, gold does not do that it seems.

Differential revision: http://reviews.llvm.org/D15564

llvm-svn: 256693
2016-01-02 16:55:01 +00:00
George Rimar 57286644f7 [ELF] - Optimize .eh_frame section: remove CIE if all FDEs referencing it were removed.
This patch performs little optimization for eh_frame section.
If all FDE`s that referenced CIE are removed then CIE is also removed from output. 
That can happen for example when dropping FDEs that point to dropped sections. Testcase showing that is included.
The same optimization was added to ld about 14 years ago: https://sourceware.org/ml/binutils/2001-12/msg00144.html, gold does not do that it seems.

Differential revision: http://reviews.llvm.org/D15564

llvm-svn: 256638
2015-12-30 11:40:44 +00:00
Simon Atanasyan 69b3cbef43 [ELF][MIPS] Rename test file. NFC
llvm-svn: 256577
2015-12-29 21:09:26 +00:00
George Rimar 4b5346fa49 Reformat of conditions for calculating r_offset in RelocationSection<ELFT>::writeTo(). NFC.
llvm-svn: 256563
2015-12-29 16:17:32 +00:00
Rui Ueyama 1a311f1da6 Split Writer::assignAddresses. NFC.
llvm-svn: 256449
2015-12-26 10:52:26 +00:00
Rui Ueyama 5a4ae1f584 Simplify. NFC.
llvm-svn: 256448
2015-12-26 10:34:33 +00:00
Rui Ueyama 1b2a8bf643 Add comments.
llvm-svn: 256447
2015-12-26 10:22:16 +00:00
Rui Ueyama 7b7ec71fea Rename SharedCopy -> CopyRel.
Because I think CopyRel is a better name for copy relocations
than SharedCopy.

llvm-svn: 256446
2015-12-26 10:07:03 +00:00
Rui Ueyama a5d79d1676 Define SECNAME_{start,end} symbols in a separate function. NFC.
llvm-svn: 256445
2015-12-26 09:48:00 +00:00
Rui Ueyama 0168722e39 Simplify __rel[a]_iplt_{start,end} handling a bit.
Also updated a comment.

llvm-svn: 256444
2015-12-26 09:47:57 +00:00
Rui Ueyama 84417f83cc Split Writer::createSections even more. NFC.
llvm-svn: 256442
2015-12-26 07:50:41 +00:00
Rui Ueyama f18fe7b439 Split Writer::createSections. NFC.
The linker has to create __tls_get_addr, end and _end symbols.
Previously, these symbols were created in createSections().
But they are not actually related to creating output sections.
This patch moves code out of the function.

llvm-svn: 256441
2015-12-26 07:50:39 +00:00
Rui Ueyama d30e4de717 Remove dead variable.
llvm-svn: 256440
2015-12-26 07:27:10 +00:00
Rui Ueyama 63de917f75 Add comment on .eh_frame sh_type.
Also simplifies the code a bit.

llvm-svn: 256439
2015-12-26 07:13:38 +00:00
Rui Ueyama 3a1f036cc6 Define a factory class to create output sections. NFC.
Previously, this code was directly written in createSections()
function. This patch moves some code out of that function to a
new class.

llvm-svn: 256438
2015-12-26 07:01:28 +00:00
Rui Ueyama d4ea7ddd57 Do not use SpecificBumpPtrAllocator to create output sections.
The number of output sections is usually limited, so the cost
of allocating them is not a bottleneck. This patch simplifies
the code by removing the allocators.

llvm-svn: 256437
2015-12-26 07:01:26 +00:00
Rui Ueyama 40845e6d37 Use virtual function instead of hand-written type dispatch.
OutputSectionBase already has virtual member functions.
This patch makes addSection() a virtual function to remove code
from Writer::createSections().

llvm-svn: 256436
2015-12-26 05:51:07 +00:00
Simon Atanasyan 57830b60dc [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocations
The R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations use the following
expressions for calculations:
```
local symbol:  S + A + GP0 - GP
global symbol: S + A - GP

GP  - Represents the final gp value, i.e. _gp symbol
GP0 - Represents the gp value used to create the relocatable object
```
The GP0 value is taken from the .reginfo data section defined by an object
file. To implement that I keep a reference to `MipsReginfoInputSection`
in the `ObjectFile` class. This reference is used by the
`ObjectFile::getMipsGp0` method to return the GP0 value.

Differential Revision: http://reviews.llvm.org/D15760

llvm-svn: 256416
2015-12-25 13:02:13 +00:00
George Rimar a7afacae70 Fixed MSVS warning "not all control paths return a value". NFC.
llvm-svn: 256415
2015-12-25 11:15:26 +00:00
George Rimar 6ab275c0c8 [ELF] - Fixed handling relocations against zero sized .eh_frame section.
The file crtbeginT.o has relocations pointing to the start of an empty
.eh_frame that is known to be the first in the link. It does that to
identify the start of the output .eh_frame. Handle this special case.

Differential revision: http://reviews.llvm.org/D15610

llvm-svn: 256414
2015-12-25 09:51:42 +00:00
Rui Ueyama 2df0fd86c2 Split Writer::createSections().
This function was longer than 250 lines, which is way too long
in my own standard. This patch reduces the size. It is still
too long, but this patch should be toward the right direction.

llvm-svn: 256411
2015-12-25 07:38:58 +00:00
Rui Ueyama 89f4ec74c1 Move a function to a file where it is used.
llvm-svn: 256410
2015-12-25 07:01:09 +00:00
Rui Ueyama 7d332f5eb7 Add comments.
llvm-svn: 256409
2015-12-25 06:55:39 +00:00
Rui Ueyama a246e094bc Factor out static members from DefinedRegular.
This patch moves statically-allocated Elf_Sym objects out
of DefinedRegular class, so that the class definition becomes
smaller.

llvm-svn: 256408
2015-12-25 06:12:18 +00:00
Rafael Espindola 7f040bf658 Simplify. NFC.
llvm-svn: 256404
2015-12-25 01:00:41 +00:00
Rafael Espindola 91bd48a33a Update the recorded CIE length when aligning.
We cannot just pad with 0s as that would be a terminator mark.

llvm-svn: 256392
2015-12-24 20:44:06 +00:00
Rafael Espindola 1119191c4f Make it possible to create common symbols from bitcode.
Since the only missing bit was the size, I just replaced the Elf_Sym
with the size.

llvm-svn: 256384
2015-12-24 16:23:37 +00:00
Rafael Espindola 02ce26a1b4 Delete DefinedAbsolute.
There are 3 symbol types that a .bc can provide during lto: defined,
undefined, common.

Defined and undefined symbols have already been refactored. I was
working on common and noticed that absolute symbols would become an
oddity: They would be the only symbol type present in a .o but not in
a.bc.

Looking a bit more, other than the special section number they were only
used for special rules for computing values. In that way they are
similar to TLS, and we don't have a DefinedTLS.

This patch deletes it. With it we have a reasonable rule of the thumb
for having a symbol kind: It exists if it has special resolution
semantics.

llvm-svn: 256383
2015-12-24 14:22:24 +00:00
Rui Ueyama 01a65b19cf Add comments.
llvm-svn: 256380
2015-12-24 10:37:32 +00:00
Rui Ueyama 74f598b2b5 Remove `continue` to make the code a bit shorter. NFC.
llvm-svn: 256379
2015-12-24 10:14:05 +00:00
Rui Ueyama da735325fa Mark .eh_frame sections as live by default. NFC.
This change eliminates a string comparison from the
garbage collector.

llvm-svn: 256378
2015-12-24 10:08:54 +00:00
Davide Italiano b40553751a [README] Update to reflect the new world order.
llvm-svn: 256376
2015-12-24 10:03:46 +00:00
Davide Italiano bcbfedc927 [ELF] Don't reclaim .ctors/.dtors sections.
In FreeBSD, rtld expects .ctors containing -1 (0xffffffff), and a
.ctors section containing the correct bits is provided to the linker as
input (/usr/lib/crtbegin.o).

Contents of section .ctors:
 0000 ffffffff ffffffff                    ........

This section is not stripped even if not referenced or empty, also in
gold or ld.bfd. It would be nice to strip it when not needed but
since existing object files rely on that we can't do better to keep it
around.

Differential Revision:   http://reviews.llvm.org/D15767

llvm-svn: 256373
2015-12-24 09:52:11 +00:00
Rui Ueyama 7924fb8142 Add a comment.
llvm-svn: 256372
2015-12-24 09:50:22 +00:00
Rui Ueyama 3d312a684a Remove unnecessary explicit instantiation.
llvm-svn: 256370
2015-12-24 08:41:55 +00:00
Rui Ueyama 3f11c8c97e Split functions and add comments. NFC.
llvm-svn: 256369
2015-12-24 08:41:12 +00:00
Rui Ueyama 3bfaba928f Make a member function non-member. NFC.
llvm-svn: 256368
2015-12-24 08:37:34 +00:00
Rui Ueyama dc8d3a2104 Return early and remove a redundant error check. NFC.
llvm-svn: 256367
2015-12-24 08:36:56 +00:00
Rui Ueyama 215d6a31b7 Add machine type check for MIPS-specific code path.
llvm-svn: 256355
2015-12-24 01:32:39 +00:00
Rafael Espindola 4d4b06a0f8 Split Defined and DefinedElf.
This is similar to what was done for Undefined and opens the way for
having a symbol defined in bitcode.

llvm-svn: 256354
2015-12-24 00:47:42 +00:00
Rafael Espindola ae53324cd4 Move function to the file where it is used.
llvm-svn: 256348
2015-12-23 20:37:51 +00:00
Rafael Espindola 97cbe3e39c Place RW sections that go after relro to another memory page.
Before this patch sections that go after relro sequence were placed at
the same memory page with relro ones. It caused segmentation fault on
freebsd.

Fixes PR25790.

Patch by George Rimar with some tweaks by myself.

llvm-svn: 256334
2015-12-23 15:20:38 +00:00
Rafael Espindola 21f7bd4ba1 Simplify memory management.
We no longer need an explicit delete or a polymorphic destructor.

llvm-svn: 256333
2015-12-23 14:35:51 +00:00
Rafael Espindola ce7d39d5e1 Fix the last leak asan found in test/ELF.
llvm-svn: 256316
2015-12-23 03:40:17 +00:00
Rafael Espindola 7300afa36a Fix another asan detected leak.
llvm-svn: 256311
2015-12-23 01:18:40 +00:00
Rafael Espindola 05b0375e93 Fix an asan found leak.
I will make better use of std::unique_ptr in followup patch.

llvm-svn: 256310
2015-12-23 01:14:37 +00:00