Commit Graph

2810 Commits

Author SHA1 Message Date
Rui Ueyama aade0e29ad Add single quotes to a warning message for consistency.
llvm-svn: 287197
2016-11-17 03:32:41 +00:00
Davide Italiano c223d1bc6b [ELF] Don't replace path separators on *NIX.
Apparently this is wrong because it's legal to have a filename
on UNIX which contains a backslash.

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

llvm-svn: 287143
2016-11-16 19:35:36 +00:00
Rafael Espindola 95eae57d78 Don't error if __tls_get_addr is defined.
Turns out some systems do define it. Not producing an error in this
case matches gold and bfd.

llvm-svn: 287125
2016-11-16 18:01:41 +00:00
George Rimar e0fc24210d [ELF] - Added support for extern "c++" local symbols in version script.
Previously we did not support them,
patch implements this functionality

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

llvm-svn: 287124
2016-11-16 17:59:10 +00:00
George Rimar 7759e5b61b [ELF] - Change error message according to review comment. NFC.
Forgot about that, I am sorry.

llvm-svn: 287123
2016-11-16 17:45:45 +00:00
George Rimar 76f429b4db [ELF] - Improve diagnostic messages.
Particulaty "cannot preempt symbol" message
is extended with locations now.

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

llvm-svn: 287120
2016-11-16 17:24:06 +00:00
Rui Ueyama cb87675186 Define -build-id=tree as a synonym for -build-id=sha1.
Our build-id is a tree hash anyway, so I'll define this as a synonym
for sha1. GNU gold takes this parameter, so this is for compatibility
with that.

llvm-svn: 287119
2016-11-16 17:14:11 +00:00
Eugene Leviant afaa934304 [ELF] Add Section() to expression object
This allows making symbols containing ADDR(section) synthetic,
and defining synthetic symbols outside SECTIONS block.

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

llvm-svn: 287090
2016-11-16 09:49:39 +00:00
George Rimar f3c143188d [ELF] - Better diagnostic for "can't create dynamic relocation" error.
Patch improves message to show locations for
"can't create dynamic relocation" error.

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

llvm-svn: 287086
2016-11-16 08:34:19 +00:00
Davide Italiano 197f07e650 [ELF] Update lld now that ELF.h in LLVM has been converted to Expected.
llvm-svn: 287082
2016-11-16 05:11:30 +00:00
Rui Ueyama c91f716643 PDB: Add "* Linker *" module.
The added module contains nothing, but it is still useful as a test
to ensure that we are emitting modules that can be read back.

llvm-svn: 287071
2016-11-16 01:10:46 +00:00
Rui Ueyama 569851f1d6 Partially revert r287009: Remove trailing whitespace.
This reverts part of r287009 because I accidentally changed binary files.

llvm-svn: 287010
2016-11-15 19:09:13 +00:00
Rui Ueyama d7cfb1b6dd Remove trailing whitespace.
llvm-svn: 287009
2016-11-15 19:07:17 +00:00
George Rimar 7beff42f8f [ELF] - Do not create reserved symbols in case of relocatable output.
This patch stops creating symbols like __ehdr_start, 
_end/_etext_edata,__tls_get_addr when using -r.

This fixes PR30984.

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

llvm-svn: 286941
2016-11-15 08:19:02 +00:00
George Rimar 463984d4bf [ELF] - Better diagnostic for relative relocation to an absolute value error.
Patch adds a filename to that error message.

I faced next error when debugged one of FreeBSD port:
error: relocation R_X86_64_PLT32 cannot refer to absolute symbol __tls_get_addr

error message was poor and this patch improves it to show the locations 
of symbol declaration and using.

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

llvm-svn: 286940
2016-11-15 08:07:14 +00:00
George Rimar 308752e474 [ELF] - Allow symbols of STT_NOTYPE to be associated with SHT_SYMTAB sections.
Found this when tried to link lang/ccl FreeBSD port.
Issue is very close to D23201.
This is the reason of lang/ccl port link fail.

GNU assembler 2.17.50 [FreeBSD] 2007-07-03 could generate broken objects,
where notype symbols are associated with symtab:
...
[ 9] .symtab           SYMTAB           0000000000000000  00003c78
     0000000000006858  0000000000000018          10   803     8
...
192: 000000000000000d     0 NOTYPE  LOCAL  DEFAULT    9 _cons_org

Patch allows to handle such objects.

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

llvm-svn: 286939
2016-11-15 07:56:28 +00:00
Rui Ueyama f83806a8ad Identify object files compiled with cl.exe /GL.
Object files compiled with cl.exe /GL contain intermediate code for LTO.
We can't (and don't want to) interpret such code, but we should print
out a user-friendly error message.

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

llvm-svn: 286921
2016-11-15 01:01:51 +00:00
Rui Ueyama ec2595d2e1 Attempt to fix freaky bot.
I don't really understand what is failing on lld-x86_64-darwin13 bot,
but this patch should at least reduces the number of moving parts.

llvm-svn: 286876
2016-11-14 19:50:10 +00:00
Davide Italiano ccf2fa1cb6 [ELF] Clarify why `lld -flavor gnu` is used.
Pointed out by Rafael!

llvm-svn: 286857
2016-11-14 18:20:20 +00:00
Rafael Espindola f7a1744803 Fix program header propagation.
Propagate program headers by walking the commands, not the
sections. This allows us to propagate program headers even from
sections that don't end up in the output.

Fixes pr30997.

llvm-svn: 286837
2016-11-14 15:39:38 +00:00
George Rimar 95d7cfdf50 [ELF] - Simplify edata-etext.s test. NFC.
llvm-svn: 286810
2016-11-14 10:33:53 +00:00
George Rimar 4bcb9d6c3c [ELF] - Untabify. NFC.
llvm-svn: 286800
2016-11-14 09:33:38 +00:00
George Rimar bb6c01e7c3 [ELF] - Add support for locals list in version script.
Previously we did not support anything except "local: *", patch changes that.

Actually GNU rules of proccessing wildcards are more complex than that (http://www.airs.com/blog/archives/300):
There are 2 iteration for wildcards, at first iteration "*" wildcards are ignored and handled at second iteration.

Since we previously decided not to implement such complex rules,
I suggest solution that is implemented in this patch. So for "local: *" case nothing changes,
but if we have wildcarded locals,
they are processed before wildcarded globals. 

This should fix several FreeBSD ports, one of them is jpeg-turbo-1.5.1 and
currently blocks about 5k of ports.

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

llvm-svn: 286713
2016-11-12 07:04:15 +00:00
Rui Ueyama 09e0b5f2c9 Emit Section Contributions.
Differential Revision: https://reviews.llvm.org/D26211

llvm-svn: 286684
2016-11-12 00:00:51 +00:00
Rafael Espindola ad004470fe Add missing REQUIRES.
llvm-svn: 286666
2016-11-11 23:10:22 +00:00
Rafael Espindola 1960bcd710 Don't sort sections in -r links.
Unlike gold, bfd, gas or MC we were putting exidx sections first since
they are ro.

The spec doesn't explicitly say that they must come after, but it is
definitely more convenient for the consumer, matches other producers
and matches other areas in ELF (like SHT_GROUP) where sections are
ordered in a natural way.

llvm-svn: 286659
2016-11-11 22:43:27 +00:00
Rafael Espindola eb1c2a0dac Make test more strict. NFC.
It was non-obvious that a CHECK was not matching the following section.

llvm-svn: 286643
2016-11-11 22:07:15 +00:00
Rafael Espindola d4372f783b Avoid a crash with -r and .comment.
We would create a MergeInputSection for the synthetic .comment and
crash trying to add it to a regular output section.

With this we just don't add the synthetic section with -r. That is
consistent with gold that doesn't create .note.gnu.gold-version with
-r.

llvm-svn: 286635
2016-11-11 21:36:25 +00:00
George Rimar e893689331 [ELF] - Use backward slashes inside response files
Patch replaces forward slashes with backward inside response.txt

This is https://llvm.org/bugs/show_bug.cgi?id=30951.

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

llvm-svn: 286589
2016-11-11 13:23:13 +00:00
Davide Italiano c520e18ce0 [lld/COFF] Don't round alignment if it's already a power-of-two.
This matches link.exe behaviour.

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

llvm-svn: 286553
2016-11-11 02:53:48 +00:00
Rui Ueyama 3da3f06dd3 Include version string into ".comment" section.
Summary:
This patch adds a ".comment" section to an output. The comment
section contains the linker's version string. You can now
find out whether a binary is created by LLD or not using objdump
command like this.

  $ objdump -s -j .comment foo

  foo:     file format elf64-x86-64

  Contents of section .comment:
   0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
   0010 382e342d 32756275 6e747531 7e31342e  8.4-2ubuntu1~14.
   ...
   00c0 766d2f74 72756e6b 20323835 38343629  vm/trunk 285846)
   00d0 004c696e 6b65723a 204c4c44 20342e30  .Linker: LLD 4.0
   00e0 2e302028 7472756e 6b203238 36343036  .0 (trunk 286406
   00f0 2900                                 ).

Compilers emits .comment section as well, so the output contains
both compiler and linker information.

Alternative considered:

I first tried to add a SHT_NOTE section because GNU gold does that.
A NOTE section starts with a header which contains content type.
It turned out that ld.gold sets type NT_GNU_GOLD_VERSION to their
NOTE section. So the NOTE type is only for GNU gold (surprise!)

Next, I tried to create ".linker-version" section. However, it seems
that reusing the existing ".comment" section is better because 1)
other tools already know about .comment section and is able to strip
it and 2) the result contans not only linker info but also compiler
info.

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

llvm-svn: 286496
2016-11-10 20:20:37 +00:00
Davide Italiano 604d313816 [LTO] Call llvm_shutdown on early exit.
In a non-LTO build is a nop. In a LTO build, we deallocate/destroy
managed static and this allows us to get the output of, e.g.,
-time-passes without performing a full shutdown.

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

llvm-svn: 286493
2016-11-10 19:39:05 +00:00
Rafael Espindola 9f0c4bb795 Parse relocations only once.
Relocations are the last thing that we wore storing a raw section
pointer to and parsing on demand.

With this patch we parse it only once and store a pointer to the
actual data.

The patch also changes where we store it. It is now in
InputSectionBase. Not all sections have relocations, but most do and
this simplifies the logic. It also means that we now only support one
relocation section per section. Given that that constraint is
maintained even with -r with gold bfd and lld, I think it is OK.

llvm-svn: 286459
2016-11-10 14:53:24 +00:00
George Rimar 1a33c0f242 [ELF] - Implemented --symbol-ordering-file option.
Patch allows to pass a symbols file to linker.
LLD will map symbols to sections and sort sections
in output according to symbol ordering file.

That can help to reduce the startup time and/or
amount of pagefaults during startup.

Also, interesting benchmark result was produced by Rafael Espíndola. 
After applying the symbols file for clang he timed compiling 
X86MCTargetDesc.ii to an object file.  

The page faults went from just
56,988 to 56,946 since most faults are not in the binary.
Running time went from 4.403053515 to 4.178112244. 
The speedup seems to be because of better cache
locality.

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

llvm-svn: 286440
2016-11-10 09:05:20 +00:00
Simon Atanasyan fa03b0fafa [ELF][MIPS] Convert .MIPS.abiflags section to synthetic input section
Previously, we have both input and output section for .MIPS.abiflags.
Now we have only one class for .MIPS.abiflags, which is MipsAbiFlagsSection.
This class is a synthetic input section.

.MIPS.abiflags sections are handled as regular sections until
the control reaches Writer. Writer then aggregates all sections
whose type is SHT_MIPS_ABIFLAGS to create a single synthesized
input section. The synthesized section is then processed normally
as if it came from an input file.

llvm-svn: 286398
2016-11-09 21:37:06 +00:00
Simon Atanasyan ce02cf0099 [ELF][MIPS] Convert .reginfo and .MIPS.options sections to synthetic input sections
Previously, we have both input and output sections for .reginfo and
.MIPS.options. Now for each such sections we have one synthetic input
sections: MipsReginfoSection and MipsOptionsSection respectively.

Both sections are handled as regular sections until the control reaches
Writer. Writer then aggregates all sections whose type is SHT_MIPS_REGINFO
or SHT_MIPS_OPTIONS to create a single synthesized input section. In that
moment Writer also save GP0 value to the MipsGp0 field of the corresponding
ObjectFile. This value required for R_MIPS_GPREL16 and R_MIPS_GPREL32
relocations calculation.

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

llvm-svn: 286397
2016-11-09 21:36:56 +00:00
Rui Ueyama d43b7e8d10 Disable cpio test on Windows again.
The last fix is unlikely to solve the issue. Reverting it to the
original file.

llvm-svn: 286393
2016-11-09 20:54:01 +00:00
Rui Ueyama 2816452503 Attempt to fix green dragon bot.
llvm-svn: 286392
2016-11-09 20:42:34 +00:00
George Rimar 1feb2f7d93 [ELF] - Enable reproduce-error.s under windows.
Differential revision: https://reviews.llvm.org/D26445

llvm-svn: 286364
2016-11-09 13:55:30 +00:00
Peter Smith 8339bbd759 [ELF] ARM and AArch64 undefined weak reference values
The ARM 32 and 64-bit ABI does not use 0 for undefined weak references
that are used in PC relative relocations. In particular:
- A branch relocation to an undefined weak resolves to the next
  instruction. Effectively making the branch a no-op
- In all other cases the symbol resolves to the place so that S + A - P
  resolves to A.

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

llvm-svn: 286353
2016-11-09 10:22:29 +00:00
Eugene Leviant 166c99b37e [ELF] Attempt to fix buildbot (duplicate _gp symbol)
llvm-svn: 286247
2016-11-08 16:44:48 +00:00
Eugene Leviant 825e538559 [ELF] Better error reporting for duplicate symbol
Differential revision: https://reviews.llvm.org/D26397

llvm-svn: 286244
2016-11-08 16:26:32 +00:00
Eugene Leviant c5079dc3cc [ELF] Test case update (orphan.s)
llvm-svn: 286226
2016-11-08 11:11:23 +00:00
Eugene Leviant bae1c656bb [ELF] Heuristic for placing orphan section
Differential revision: https://reviews.llvm.org/D25325

llvm-svn: 286225
2016-11-08 10:44:48 +00:00
George Rimar 364b59e266 [ELF] - Implemented threaded --build-id computation
Patch switches computing of --build-id hash to tree.

This is the way when input data is splitted by chunks,
hash is computed for each one in threaded/non-threaded way.
At the end hash is conputed for result tree.

With or without -threads the result hash is the same.

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

llvm-svn: 286061
2016-11-06 07:42:55 +00:00
Rui Ueyama e8a6102fa9 Rewrite CommonInputSection as a synthetic input section.
A CommonInputSection is a section containing all common symbols.
That was an input section but was abstracted in a different way
than the synthetic input sections because it was written before
the synthetic input section was invented.

This patch rewrites CommonInputSection as a synthetic input section
so that it behaves better with other sections.

llvm-svn: 286053
2016-11-05 23:05:47 +00:00
Simon Atanasyan 9e0297b8bc [ELF][MIPS] N32 ABI support
In short the patch introduces support for linking object file conform
MIPS N32 ABI [1]. This ABI is similar to N64 ABI but uses 32-bit
pointer size.

The most non-trivial requirement of this ABI is one more relocation
packing format. N64 ABI puts multiple relocation type into the single
relocation record. The N32 ABI uses series of successive relocations
with the same offset for this purpose. In this patch, new function
`mergeMipsN32RelTypes` handle this case and "convert" N32 relocation to
the N64 relocation so the rest of the code keep unchanged.

For now, linker does not support series of relocations applied to sections
without SHF_ALLOC bit. Probably later I will add the support or insert
some sort of assert into the `relocateNonAlloc` routine to catch this
case.

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf

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

llvm-svn: 286052
2016-11-05 22:58:01 +00:00
Rui Ueyama 3a6f331d2d Fix buildbot.
llvm-svn: 286028
2016-11-04 23:26:29 +00:00
Rui Ueyama a9ee8d6ecc Don't gc .interp section.
This change fixes a bug that was introduced by r285851.
r285851 converted .interp section as an output section to an input
section. But I forgot to make it a "Live" section, so if -gc-section
is given, it was garbage collected.

llvm-svn: 286025
2016-11-04 22:25:39 +00:00
Rafael Espindola 22e9a8e366 Update for llvm change.
llvm-svn: 285962
2016-11-03 20:17:25 +00:00