Commit Graph

6912 Commits

Author SHA1 Message Date
Eugene Leviant b71d6f7a72 [ELF] Linker script: implement LOADADDR
Differential revision: https://reviews.llvm.org/D24298

llvm-svn: 283429
2016-10-06 09:39:28 +00:00
George Rimar 24adce95b2 [ELF] - Make checks in ObjectFile<ELFT>::getSection() stricter.
This patch makes the check for null section stricter, 
so it is only allowed for STT_SECTION symbols now.

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

llvm-svn: 283426
2016-10-06 09:17:55 +00:00
Rui Ueyama 8d3fb5da7b Add exact number of streams for reserved stream #s.
llvm-svn: 283397
2016-10-05 22:08:58 +00:00
Rui Ueyama d381c9842b Add an empty IPI stream.
With this, "llvm-pdbdump yaml -ipi-stream" prints out an IPI stream.
Previously it crashed because it can't handle the case where IPI
stream doesn't exist.

llvm-svn: 283392
2016-10-05 21:37:25 +00:00
Rui Ueyama a03380808c Early continue. NFC.
llvm-svn: 283382
2016-10-05 21:06:32 +00:00
Rui Ueyama b66260ac17 Remove trailing whitespace.
llvm-svn: 283372
2016-10-05 20:09:50 +00:00
Rafael Espindola 5fc2b1d2fe Store the hash in SectionPiece.
This spreads out computing the hash and using it in a hash table. The
speedups are:

firefox
  master 6.811232891
  patch  6.559280249 1.03841162939x faster
chromium
  master 4.369323666
  patch  4.33171853 1.00868134338x faster
chromium fast
  master 1.856679971
  patch  1.850617741 1.00327578725x faster
the gold plugin
  master 0.32917962
  patch  0.325711944 1.01064645023x faster
clang
  master 0.558015452
  patch  0.550284165 1.01404962652x faster
llvm-as
  master 0.032563515
  patch  0.032152077 1.01279662275x faster
the gold plugin fsds
  master 0.356221362
  patch  0.352772162 1.00977741549x faster
clang fsds
  master 0.635096494
  patch  0.627249229 1.01251060127x faster
llvm-as fsds
  master 0.030183188
  patch  0.029889544 1.00982430511x faster
scylla
  master 3.071448906
  patch  2.938484138 1.04524944215x faster

This seems to be because we don't stall as much. When linking firefox
stalled-cycles-frontend goes from 57.56% to 55.55%.

With -O2 the difference is even more significant since we avoid
recomputing the hash. For firefox we go from 9.990295265 to
 9.149627521 seconds (1.09x faster).

llvm-svn: 283367
2016-10-05 19:36:02 +00:00
Rafael Espindola 32aca87bf8 Compact SectionPiece.
It is pretty easy to get the data from the InputSection, so we don't
have to store it.

This opens the way for storing the hash instead.

llvm-svn: 283357
2016-10-05 18:40:00 +00:00
Rafael Espindola 939e9493bf Simplify setting the Live bit in SectionPiece. NFC.
llvm-svn: 283340
2016-10-05 17:02:09 +00:00
Rafael Espindola 7b8bb53e94 Remove redundant check. NFC.
llvm-svn: 283328
2016-10-05 15:35:18 +00:00
Eugene Leviant a8d12ef853 Do not join sections for relocatable object files
Differential revision: https://reviews.llvm.org/D25232

llvm-svn: 283307
2016-10-05 10:10:45 +00:00
Eugene Leviant cf43f179b1 [ELF] make KEEP command recognize file patterns
Differential revision: https://reviews.llvm.org/D25242

llvm-svn: 283305
2016-10-05 09:36:59 +00:00
Simon Atanasyan 02b9c3f8c3 [ELF] Do not merge sections in case of relocatable object generation
Do not merge sections if generating a relocatable object. It makes
the code simpler because we do not need to update relocations addends
to reflect changes introduced by merging. Instead of that we write
such "merge" sections into separate OutputSections and keep SHF_MERGE
/ SHF_STRINGS flags and sh_entsize value to be able to perform merging
later during a final linking.

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

llvm-svn: 283300
2016-10-05 07:49:18 +00:00
Mehdi Amini ec4fb5ba97 Use StringRef in StringSaver API (NFC)
llvm-svn: 283290
2016-10-05 01:32:41 +00:00
Rafael Espindola 259d645147 Update for llvm change.
llvm-svn: 283267
2016-10-04 22:43:38 +00:00
Rui Ueyama af9793d1c1 Add a comment.
llvm-svn: 283229
2016-10-04 16:47:49 +00:00
George Rimar e252538107 [ELF] - Do not crash on MIPS if there is no object files in input.
If we have input without object files, for example if we have only .so
code crashes in checkFlags(), getPicFlags(), getArchFlags() functions.

Patch fixes the issue.

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

llvm-svn: 283226
2016-10-04 15:19:20 +00:00
Eugene Leviant b90f3cf15b [ELF] Don't discard excluded section if -r is used
This conforms to GNU ld/gold behavior and fixes crash in case
excluded section also has associated relocation section

llvm-svn: 283214
2016-10-04 12:05:42 +00:00
George Rimar 40be15cfb0 [ELF] - Removed "invalid-" prefix from testcase. NFC.
llvm-svn: 283213
2016-10-04 11:51:38 +00:00
George Rimar 422e47a9f5 [ELF] - Do not hang if broken object has option descriptor in .MIPS.options with size of zero.
Previously lld would hang in infinite loop in this case,
patch fixes the issue. Object was found during AFL run.

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

llvm-svn: 283208
2016-10-04 10:23:07 +00:00
George Rimar b1f78d1202 [ELF] - Do not crash on invalid symbol index.
Relative to PR30540.

If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.

This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"

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

llvm-svn: 283201
2016-10-04 09:02:42 +00:00
Eugene Leviant ee8dcfbdf7 [ELF] Set max page size to 64K for AArch64
Differential revision: https://reviews.llvm.org/D25079

llvm-svn: 283200
2016-10-04 08:58:55 +00:00
George Rimar 6a3b154aab [ELF] - Do not crash if symbol type set to TLS when there is no tls sections.
id_000021,sig_11,src_000002,op_flip1,pos_92 from PR30540

does not have TLS sections, but type
of one of the symbol is broken and set to STT_TLS,
what resulted in a crash. Patch fixes crash.

DIfferential revision: https://reviews.llvm.org/D25083

llvm-svn: 283198
2016-10-04 08:52:51 +00:00
George Rimar 0c82561c4c [ELF] - Do not crash if common symbol has alignment 0.
Testcase contains a common symbol with zero alignment,
previously lld would crash, patch fixes that.

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

llvm-svn: 283197
2016-10-04 08:49:52 +00:00
Simon Atanasyan 3a61cabbb2 [ELF][MIPS] Do not accept non-zero GP0 value for relocatable object only
Follow-up to r282716. Reject input files with non-zero GP0 value only in
case of relocatable object generation. In other case we can handle
arbitrary GP0 value so it does not have a sense to make the restriction
so wide.

llvm-svn: 283194
2016-10-04 08:24:25 +00:00
Rui Ueyama ab8e88b686 Remove unused parameter.
I do not fully understand how to use these classes yet, but
seems like these arguments are not used, since without them
all tests still pass. In order to simplify the situation,
I'll remove them now.

llvm-svn: 283174
2016-10-04 01:03:03 +00:00
Rui Ueyama ad9268a7b4 Early return. NFC.
llvm-svn: 283173
2016-10-04 00:46:36 +00:00
George Rimar 10874f70fa [ELF] - Apply clang-format. NFC.
llvm-svn: 283101
2016-10-03 11:13:55 +00:00
George Rimar 2c0a7f081a [ELF] - Do not crash on invalid section alignment.
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.

Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.

Patch fixes the issue.

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

llvm-svn: 283097
2016-10-03 10:04:38 +00:00
Rui Ueyama c79ecdd876 Use StringSwtich::Cases for multiple choices.
llvm-svn: 282964
2016-09-30 22:01:25 +00:00
Rui Ueyama 129795497d Change for LLVM upstream change r282944.
llvm-svn: 282945
2016-09-30 20:53:45 +00:00
Rui Ueyama 5c82eeaf23 Change for LLVM change r282940.
llvm-svn: 282942
2016-09-30 20:39:04 +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 eb0007aa0c Remove an warning message that can be spammy.
This was intended to warn on a usage error of an ar command.
I was thinking that false positive would be rare because it
has two guards: it warns only when an archive file has no symbols
and contains at least one file.

Turned out that false positive would probably be not that rare.
You wouldn't intentionally create an object file that contains no
exported symbols, but with conditional compile guards, you could
create such file. If it is for a LTO build, you could create an
archive file containing such file. That means there's no way to
detect the usage error in a reliable manner.

This patch simply removes the warning.

llvm-svn: 282916
2016-09-30 19:59:25 +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
George Rimar f50bafc708 [ELF] - Inlined template argument variable. NFC.
llvm-svn: 282851
2016-09-30 13:46:34 +00:00
George Rimar 3da3ffa67f [ELF] - Removed excessive variables. NFC.
llvm-svn: 282850
2016-09-30 13:44:02 +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
Rui Ueyama e364d1f431 Add comments.
llvm-svn: 282807
2016-09-29 23:04:50 +00:00
Rafael Espindola 2d68f8ade4 Break long line. NFC.
llvm-svn: 282806
2016-09-29 23:02:57 +00:00
Rui Ueyama 541f48d0fc Use StringSwitch::Cases. NFC.
llvm-svn: 282802
2016-09-29 22:54:31 +00:00
Rui Ueyama 5b8a3b3262 Remove HasError check after lto::LTO::run.
Because LTO::run doesn't change HasError, it doesn't make
sense to check that value.

llvm-svn: 282801
2016-09-29 22:50:37 +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
Rui Ueyama 1cc007aeae Keep a private member private.
llvm-svn: 282798
2016-09-29 22:37:45 +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
Rui Ueyama 1375a9bdc6 Remove a return type that can be trivially easily.
llvm-svn: 282795
2016-09-29 22:14:20 +00:00
Rui Ueyama 6c5cbff97e Rename "void check(Error)".
We have a few "check" functions in Error.h. All of them are to
check for an error and strip an error object if there was no error,
except "void check(Error E)", which doesn't return anything.
This patch renames it and moves it to the .cpp file where it is used.

llvm-svn: 282764
2016-09-29 21:00:26 +00:00
Rui Ueyama d31e13f287 Rename warning -> warn.
It's better because it's a verb.

llvm-svn: 282763
2016-09-29 21:00:23 +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
Rafael Espindola c94678bf72 Simplify. NFC.
llvm-svn: 282725
2016-09-29 16:29:55 +00:00
Rafael Espindola 4e96895385 Don't handle binary output differently.
It is not clear if we need a different layout, so for now handle them
like regular ELF output.

llvm-svn: 282724
2016-09-29 16:24:17 +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
Rui Ueyama 0f327380bf Attempt to fix Windows buildbots.
llvm-svn: 282670
2016-09-29 01:59:03 +00:00
Rui Ueyama e8b2df47a3 Remove unused #includes.
llvm-svn: 282668
2016-09-29 01:45:22 +00:00
Rui Ueyama ed1414b83c Add comments.
llvm-svn: 282664
2016-09-29 01:26:48 +00:00
Rafael Espindola 615c5ae7ae Read addend from the correct location.
llvm-svn: 282663
2016-09-29 01:20:40 +00:00
Davide Italiano c985e8b341 [LTO] Fully qualify make_unique to make MSVC happy.
llvm-svn: 282662
2016-09-29 01:13:32 +00:00
Rui Ueyama d72dd1fc4e Use InputFile::Symbol instead of auto for consistency.
llvm-svn: 282658
2016-09-29 00:58:10 +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
Rafael Espindola 5217f8452c Sort headers. NFC.
llvm-svn: 282603
2016-09-28 16:31:05 +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
Rafael Espindola a42b3bcae4 Use xxhash for fast --build-id.
The speed improvements I got were:

firefox
  master 7.050784981
  patch  6.842361079 0.970439617353
chromium
  master 4.260626249
  patch  4.183148025 0.981815296749
chromium fast
  master 1.829028591
  patch  1.806439277 0.987649556649
the gold plugin
  master 0.336154128
  patch  0.331893374 0.987324998728
clang
  master 0.561869781
  patch  0.558640828 0.994253200458
llvm-as
  master 0.034025959
  patch  0.033984389 0.99877828572
the gold plugin fsds
  master 0.360710529
  patch  0.356483564 0.988281559145
clang fsds
  master 0.640518422
  patch  0.632329874 0.987215749432
llvm-as fsds
  master 0.031569416
  patch  0.030822055 0.976326423017
scylla
  master 3.154770529
  patch  3.11982016 0.988921422754

llvm-svn: 282505
2016-09-27 16:43:49 +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
Rui Ueyama 3e9d6bbad6 Create FileOutputBuffer lazily.
So that it is clear that FileOutputBuffer does not depend on
PDB file builder. Eventually we will have to to get the file size
info from the file builder to create a file with the exact size.
NFC.

llvm-svn: 282454
2016-09-26 23:53:55 +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
George Rimar f28210285b [ELF] - Format. NFC.
llvm-svn: 282395
2016-09-26 11:00:48 +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
Rui Ueyama 9c4ac5f26c Combine two StringSwitch::Cases because Cases now can take 6 parameters.
llvm-svn: 282307
2016-09-23 22:22:34 +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
Rui Ueyama 0120e3f278 Simplify. NFC.
llvm-svn: 282268
2016-09-23 18:06:51 +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