Commit Graph

2652 Commits

Author SHA1 Message Date
Rui Ueyama 129795497d Change for LLVM upstream change r282944.
llvm-svn: 282945
2016-09-30 20:53:45 +00:00
Rui Ueyama 062d7e4911 Removed a test that should've been removed with r282916.
llvm-svn: 282926
2016-09-30 20:17:26 +00:00
Rui Ueyama 3d0f77b281 Improve error check for an empty archive.
Previously, it warned on any archive file that has no symbol.
It turned out that that is too noisy.

With this patch, it warns on such archive file that contains no file.

Differential Revision: https://reviews.llvm.org/D25111

llvm-svn: 282885
2016-09-30 17:56:20 +00:00
Rafael Espindola 2629602f28 Fix another --gc-sections crash.
The missing case was when a merge section was only referenced from
non-alloca sections.

llvm-svn: 282847
2016-09-30 06:48:09 +00:00
Rafael Espindola c1eff79f61 Fix --gc-sections crash.
We would crash when a non-alloca section pointed to a gced part of a
merge section.

That can happen when a C/c++ constant in put in a merge section and
debug info is present.

llvm-svn: 282845
2016-09-30 06:37:29 +00:00
Rafael Espindola be6073345e Start linker scripts at 0.
We were implicitly creating space for the headers. That is not the
behaviour of bfd, which requires the script to use SIZEOF_HEADERS. The
difference is important for scripts that don't use SIZEOF_HEADERS and
expect the first section to be at 0.

llvm-svn: 282818
2016-09-30 00:16:11 +00:00
Rafael Espindola 317c339f61 Don't depend on lld creating space for the headers.
Currently lld will implicitly reserve space for the headers. This is
not the case is bfd, where it is the script responsibility to use
SIZEOF_HEADERS. This means that a script not using SIZEOF_HEADERS and
expecting the address of the first section to be 0 would fail with lld.

I am fixing that is the next commit. This one just makes the tests
explicitly use SIZEOF_HEADERS to avoid the dependency on the current
behaviour.

llvm-svn: 282814
2016-09-30 00:06:24 +00:00
Rafael Espindola 2d68f8ade4 Break long line. NFC.
llvm-svn: 282806
2016-09-29 23:02:57 +00:00
Rafael Espindola e979fd1bf0 Don't put ro before rx when using linker scripts.
Since they end up going on the same PT_LOAD, there is no reason to
sort them. This matches bfd's behaviour and is user visible in the
placement of orphan sections.

llvm-svn: 282799
2016-09-29 22:48:55 +00:00
Rafael Espindola 475f2ccf98 List more sections in linker script.
This makes the test less brittle with regards to orphan section placement.

llvm-svn: 282797
2016-09-29 22:27:48 +00:00
Rafael Espindola f084edf40e Use > and not >> to create the script.
llvm-svn: 282760
2016-09-29 20:23:07 +00:00
Rafael Espindola 6d91fce526 Don't error if we can't put the header in a PT_LOAD.
If there is not sufficient address space, just give up and don't put
the header in the PT_LOAD.

This matches bfd behaviour and I found at least one script that
depends on having a section at address 0.

llvm-svn: 282750
2016-09-29 18:50:34 +00:00
Simon Atanasyan 353fc1e947 [ELF][MIPS] Set GP0 value to zero in case of relocatable object generation
LLD does not update relocations addends when generate a relocatable
object. That is why we should not write a non-zero GP0 value into
the .reginfo and .MIPS.options sections. And we should not accept input
object files with non-zero GP0 value because we cannot handle them
properly.

llvm-svn: 282716
2016-09-29 12:58:48 +00:00
Simon Atanasyan f4a1d8d0e0 [ELF][MIPS] Do not use a binary input file in the test case. NFC
llvm-svn: 282715
2016-09-29 12:58:42 +00:00
Simon Atanasyan f967f090b8 [ELF][MIPS] Setup STO_MIPS_PIC flag for PIC symbols when generate a relocatable object
In case of linking PIC and non-PIC code together and generation of a
relocatable object, all PIC symbols should have STO_MIPS_PIC flag in the
symbol table of the ouput file.

llvm-svn: 282714
2016-09-29 12:58:36 +00:00
George Rimar 678bd05740 [ELF] - Fixed crash on invalid input.
I took the input from https://llvm.org/bugs/show_bug.cgi?id=30540, it was
"id_000000,sig_11,src_000000,op_flip1,pos_98"

File contains invalid symbol name offset (too large) and lld just crashes,
patch fixes the issue.

Differential revision: https://reviews.llvm.org/D24970

llvm-svn: 282709
2016-09-29 11:10:40 +00:00
Eugene Leviant d2778848ef Don't GC non-alloc mergeable section pieces
Differential revision: https://reviews.llvm.org/D25033

llvm-svn: 282708
2016-09-29 10:27:10 +00:00
George Rimar 1abe30a762 [ELF] - Testcases: remove "invalid-" prefix from inputs located in "invalid" subfolder. NFC.
llvm-svn: 282707
2016-09-29 09:39:06 +00:00
George Rimar c017bb3f11 [ELF] - Rename testcase folder from "Invalid" to "invalid". NFC.
llvm-svn: 282706
2016-09-29 09:30:01 +00:00
Eugene Leviant 3d9abec091 [ELF] Change the way we compute file offsets
If we two sections reside in the same PT_LOAD segment,
we compute second section using the following formula:
Off2 = Off1 + VA2 - VA1. This allows OS kernel allocating
sections correctly when loading an image.

Differential revision: https://reviews.llvm.org/D25014

llvm-svn: 282705
2016-09-29 09:20:33 +00:00
Lei Liu 6fa4fe83f7 [AArch64] Fix test case ELF/aarch64-tls-le.s
The add instruction should be generated with shift bit (lsl #12).
Update the test case.

llvm-svn: 282671
2016-09-29 02:01:27 +00:00
Rafael Espindola 615c5ae7ae Read addend from the correct location.
llvm-svn: 282663
2016-09-29 01:20:40 +00:00
Davide Italiano 786d8e33db [ELF/LTO] Switch to the new resolution-based API.
Differential Revision:  https://reviews.llvm.org/D24492

llvm-svn: 282656
2016-09-29 00:40:08 +00:00
Rui Ueyama cb85d7f840 Warn on empty archive files.
Differential Revision: https://reviews.llvm.org/D25044

llvm-svn: 282633
2016-09-28 21:10:54 +00:00
Petr Hosek 997f8838e5 [ELF] Support -z max-page-size option
This options issupported by both BFD ld and gold and allows
overriding the max page size whose default values are defined by
the target.

https://llvm.org/bugs/show_bug.cgi?id=30541

Differential Revision: https://reviews.llvm.org/D24891

llvm-svn: 282596
2016-09-28 15:20:47 +00:00
George Rimar dd381c39e1 [ELF] - Created new "Invalid" subfolder for testcases.
This subfolder just like "linkerscript" subfolder keeps
testcases with invalid input. According to PR30540 it seems
we might have many new ones soon, so it is seems reasonable to 
separate them from regular testcases.

Differential revision: https://reviews.llvm.org/D25010

llvm-svn: 282595
2016-09-28 15:11:58 +00:00
Eugene Leviant 27be542cdf [ELF] Ignore sections flagged with SHF_EXCLUDE
Differential revision: https://reviews.llvm.org/D24966

llvm-svn: 282568
2016-09-28 08:42:02 +00:00
Petr Hosek 5d98fef75d [ELF] Use MaxPageSize for aligning PT_LOAD
This matches the behavior of Binutils linkers. We also change the
default MaxPageSize on x86-64 to 0x1000 to preserver the current
behavior, which is the same as the behavior implemented by gold.

https://llvm.org/bugs/show_bug.cgi?id=30541

Differential Revision: https://reviews.llvm.org/D24987

llvm-svn: 282560
2016-09-28 00:09:20 +00:00
Martin Storsjo 63762b58c0 [COFF] Add support for IMAGE_REL_ARM_SECREL
Handle this in the exact same way as IMAGE_REL_AMD64_SECREL
and IMAGE_REL_I386_SECREL.

Differential revision: https://reviews.llvm.org/D24608

llvm-svn: 282531
2016-09-27 19:27:17 +00:00
George Rimar 3150799859 [ELF] - Fixed string encoding in test. NFC.
llvm-svn: 282497
2016-09-27 15:58:31 +00:00
George Rimar 74661eb040 [ELF] - Fixed linkage error when using -g --gc-sections together.
r282444 introduced new issue, sample program below
fails to link on

assert(Piece.Live);
int main() { return 0; }
clang test.cpp -c -o out.o -g
ld.lld -flavor gnu --gc-sections out.o -o out

Problem is that .debug_info contains relocations to .debug_str:
Section (7) .rela.debug_info {
..

0xC R_X86_64_32 .debug_str 0x0
0x12 R_X86_64_32 .debug_str 0x37
..
But we do not preserve .debug_str in a right way now.

To fix this we should ignore relocations from non-allocatable sections to allocatable
to allow GC work at full power, but still should proccess relocations from non-allocatable to non-allocatable sections
as usual to mark some parts of debug sections alive to keep them so we do not end 
up with such assert when trying to access dead pieces. That looks like what gold/ld do, they do 
not strip .debug_str section from what I saw using sample provided.

Thanks to Evgeny Leviant for suggestions about how to fix this.

Differential revision: https://reviews.llvm.org/D24967

llvm-svn: 282495
2016-09-27 15:55:29 +00:00
Rafael Espindola 2b9008e5e5 Non alloca sections should not keep other sections live.
This matches the gold behaviour and is important to prevent debug info
from effectively disabling gc.

llvm-svn: 282444
2016-09-26 21:34:34 +00:00
George Rimar e38cbab5a4 [ELF] - Linkerscript: implemented BYTE/SHORT/LONG/QUAD commands.
The BYTE, SHORT, LONG, and QUAD commands store one, two, four, and eight bytes (respectively). 
After storing the bytes, the location counter is incremented by the number of bytes
stored.

Previously our scripts handles these commands incorrectly. For example:
SECTIONS  {
  .foo : {
 *(.foo.1)
 BYTE(0x11)
...
We accepted the script above treating BYTE as input section description. 
These commands are used in the wild though.

Differential revision: https://reviews.llvm.org/D24830

llvm-svn: 282429
2016-09-26 19:22:50 +00:00
George Rimar a213e6b6f5 [ELF] - Fix for: Bug 30521 - lld exits non-zero return value linking a library with no entry symbol
PR30521 was about linking shared library. After r282295 code when linking -shared produced
"entry symbol not found" warning, what in combination with --fatal-errors failed linkage.

Patch fixes logic (and adds testcases) to follow next rules:

1) If entry was specified and not found report warning.
2) If entry was not specified then:
 a) Emit warning if not -shared.
 b) Do not emit warning if -shared.

Differential revision: https://reviews.llvm.org/D24913

llvm-svn: 282427
2016-09-26 19:04:42 +00:00
Eugene Leviant 527a84ec12 Linkerscript: don't crash when GC .debug_line
Differential revision: https://reviews.llvm.org/D24870

llvm-svn: 282393
2016-09-26 09:04:16 +00:00
Eugene Leviant 8287b1bce1 Linkerscript: do not GC non-allocated sections
Differential revision: https://reviews.llvm.org/D24733

llvm-svn: 282391
2016-09-26 08:32:41 +00:00
Davide Italiano c79d196c8e [LTO] Add a test for invalid alias analysis pipelines.
I found out this wasn't tested when looking at Vedant's coverage bot
numbers, so, thanks to him. While I'm here, switch the error message
to be lld-compliant (first letter lowercase).

llvm-svn: 282335
2016-09-24 20:05:52 +00:00
Rafael Espindola 251e240adc Warn if we can't find the entry symbol.
Fixes pr30465.

llvm-svn: 282295
2016-09-23 21:04:56 +00:00
Rafael Espindola 65499b9040 Avoid counting sections twice.
We were counting the size of the bss section holding common symbols twice:

    Dot += CurOutSec->getSize();
    flush();

The new code is also simpler as now flush is the only function that
inserts in AlreadyOutputOS, which makes sense since the set hold fully
output sections.

llvm-svn: 282285
2016-09-23 20:10:47 +00:00
Davide Italiano 03f7005375 [ELF] Resolve weak undefined TLS symbols when no phdr is available.
If we pass --gc-sections to lld and .tbss is not referenced,
the section is reclaimed and lld doesn't create a TLS program header.
R_TLS tries to access the program header -> lld crashes.
Mimic what bfd/gold do in this case and resolve a weak undefined
TLS symbol to the base of the TLS block, i.e. give it a value of zero.

Differential Revision:  https://reviews.llvm.org/D24832

llvm-svn: 282279
2016-09-23 18:47:50 +00:00
Rafael Espindola cfdd1fdfb6 Fix test when run in unusual test directories.
It would fail for example if the directory contained an @. Both gold
and bfd require quotes for @, so just change the test to quote the
directory name.

Thanks to Vedant Kumar for the bug report.

llvm-svn: 282256
2016-09-23 15:34:53 +00:00
Peter Smith fde6213fe8 [ARM] ARM TLS shouldn't use relaxations
The ARM TLS relocations are placed on literal data and not the 
code-sequence, it is therefore not possible to implement the relaxTls* 
functions. This change updates handleMipsTlsRelocation() to
handleNoRelaxTlsRelocation() and incorporates ARM as well as Mips.

The ARM support in handleNoRelaxTlsRelocation() currently needs to ouput
the module index dynamic relocation in all cases as it is relying on the 
dynamic linker to set the module index in the got.

Should address PR30218

Differential Revision: https://reviews.llvm.org/D24827

llvm-svn: 282250
2016-09-23 13:54:48 +00:00
George Rimar 4ebc562052 [ELF] - Linkerscript: accept space between '=' and expression in section filler.
Previously we failed to parse next scripts because disallowed
a space between filler value and '=':

  .text : {
...
  } :text = 0x9090

Differential revision: https://reviews.llvm.org/D24831

llvm-svn: 282248
2016-09-23 13:29:20 +00:00
George Rimar f34f45fd53 [ELF] - Linkerscript: implement DEFINED() command.
DEFINED(symbol)
Return 1 if symbol is in the linker global symbol table and is defined before
the statement using DEFINED in the script, otherwise return 0.

Can be used to define default values for symbols. Found it in the wild.

Differential revision: https://reviews.llvm.org/D24858

llvm-svn: 282245
2016-09-23 13:17:23 +00:00
Eugene Leviant d4dea164dd Linker script: fix crash when discarding section
If section contains local symbols ldd crashes, because local
symbols are added to symbol table before section is discarded
by linker script processor. This patch calls copyLocalSymbols()
after createSections, so discarded section symbols are not copied

llvm-svn: 282244
2016-09-23 13:17:16 +00:00
George Rimar c8ccd1f1c5 [ELF] - Linkerscript: Implemented >> and <<
Found this operators used in the wild scripts, for example:

__got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >>2;
__fixup_entries = (. - _FIXUP_TABLE_)>>2;

Differential revision: https://reviews.llvm.org/D24860

llvm-svn: 282243
2016-09-23 13:13:55 +00:00
Davide Italiano 49ab2517f5 [ELF/GC] Don't crash while processing Discarded sections.
The ELF spec doesn't allow relocations to point directly to
a deduplicated COMDAT section but this unfortunately happens in
practice. Bail out early instead of crashing.

Differential Revision:  https://reviews.llvm.org/D24750

llvm-svn: 282197
2016-09-22 21:08:51 +00:00
Vedant Kumar 387eb83a50 [lld] Add llvm-pdbdump as a test dependency
Reviewed-by: rafael
llvm-svn: 282187
2016-09-22 20:12:23 +00:00
Rafael Espindola 29c59cc15d Remove extra \
Should fix the windows bots.

llvm-svn: 282181
2016-09-22 18:36:46 +00:00
Rafael Espindola 15c579518d Don't move orphan sections past assignments.
This fixes a case where we would produce an unaligned PT_LOAD.

llvm-svn: 282180
2016-09-22 18:05:49 +00:00