Commit Graph

2747 Commits

Author SHA1 Message Date
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 e784395c99 [ELF] - Ignore -Map,-M and --cref options.
-M, --print-map Write map file on standard output
-Map MAPFILENAME Write map file
--cref	Output cross reference table

This is relative to PR30973.

Next FreeBSD ports were atm failing because of 
lack of -Map, -M and --cref:

sysutils/openipmi
emulators/adamem
devel/jwasm
net/pimd
devel/k8048
textproc/libcrm114
lang/micropython
net/mrouted
print/openprinting

After this patch all of them can be link fine.

llvm-svn: 286831
2016-11-14 14:45:11 +00:00
Rafael Espindola 6a53737c92 Delay removing empty section commands. NFC.
To fix pr30997 we will have to keep them a bit longer, this just
splits that part of the diff.

llvm-svn: 286827
2016-11-14 14:33:49 +00:00
Rafael Espindola 07fe612973 Factor out removeEmptyCommands. NFC.
llvm-svn: 286826
2016-11-14 14:23:35 +00:00
Rafael Espindola 337f903c6c Factor out placeOrphanSections. NFC.
llvm-svn: 286824
2016-11-14 14:13:32 +00:00
George Rimar d8b27769c8 [ELF] - format. NFC.
llvm-svn: 286805
2016-11-14 10:14:18 +00:00
George Rimar 0b2d374c01 [ELF] - format. NFC.
llvm-svn: 286804
2016-11-14 10:05:53 +00:00
George Rimar 59d9b4b4bc [ELF] - Removed trailing whitespace. NFC.
llvm-svn: 286803
2016-11-14 10:04:45 +00:00
George Rimar da841c161d [ELF] - Removed unused code. NFC.
This branch was unused I believe,
as Tok can never be empty.

llvm-svn: 286802
2016-11-14 10:03:54 +00:00
George Rimar 92ca6f4b7d [ELF] - Fix mistype. NFC.
llvm-svn: 286801
2016-11-14 09:56:35 +00:00
Eugene Leviant 22eb026886 [ELF] Convert StringTableSection to input section
Differential revision: https://reviews.llvm.org/D26549

llvm-svn: 286799
2016-11-14 09:16:00 +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 da139f793c Remove dead code.
llvm-svn: 286698
2016-11-12 01:32:34 +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 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
Peter Collingbourne cd513a41c1 Bitcode: Clean up error handling for certain bitcode query functions.
The functions getBitcodeTargetTriple(), isBitcodeContainingObjCCategory(),
getBitcodeProducerString() and hasGlobalValueSummary() now return errors
via their return value rather than via the diagnostic handler.

To make this work, re-implement these functions using non-member functions
so that they can be used without the LLVMContext required by BitcodeReader.

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

llvm-svn: 286623
2016-11-11 19:50:24 +00:00
Eugene Leviant ad5cfa26f9 [ELF] Attempt to fix PPC buildbot
llvm-svn: 286590
2016-11-11 13:24:49 +00:00
Eugene Leviant 17afb64d4f [ELF] Set 'Live = true' in SyntheticSection ctor. NFC.
llvm-svn: 286588
2016-11-11 13:03:58 +00:00
Eugene Leviant ad4439e802 [ELF] Convert .got section to input section
Differential revision: https://reviews.llvm.org/D26498

llvm-svn: 286580
2016-11-11 11:33:32 +00:00
Teresa Johnson 1e390897ba Mirror the llvm changes that split Bitcode/ReaderWriter.h
The change in D26502 splits ReaderWriter.h, which contains the APIs
into both the BitReader and BitWriter libraries, into BitcodeReader.h
and BitcodeWriter.h.

Change lld uses to the appropriate split header, removing it
completely in one case where it wasn't needed.

llvm-svn: 286568
2016-11-11 05:35:22 +00:00
Mehdi Amini c1edf566b9 Prevent at compile time converting from Error::success() to Expected<T>
This would trigger an assertion at runtime otherwise.

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

llvm-svn: 286562
2016-11-11 04:29:25 +00:00
Mehdi Amini 41af43092c Make the Error class constructor protected
This is forcing to use Error::success(), which is in a wide majority
of cases a lot more readable.

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

llvm-svn: 286561
2016-11-11 04:28:40 +00:00
Rui Ueyama 82664d9d4c Remove a member from InputSectionData and use the pool instead.
llvm-svn: 286557
2016-11-11 03:54:59 +00:00
Rui Ueyama 169e7c4edc Call flush() after llvm_shutdown().
llvm_shutdown could write something to outs or errs,
so we need to flush them after calling llvm_shutdown.

llvm-svn: 286548
2016-11-11 02:16:15 +00:00
Rui Ueyama 049e045c3a Handle Archive::children's error proerly.
The previous code didn't make sense at all. Now an error condition
is handled with fatal(). Thanks to Mehdi for pointing out the issue.

llvm-svn: 286547
2016-11-11 02:09:28 +00:00
Davide Italiano b69f38f7a7 [ELF] Remove extra semicolon to placate GCC. NFCI.
llvm-svn: 286529
2016-11-11 00:05:41 +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 0e876cfb2e Replace duplicated '16' with a named constant.
Thanks to Michael Spencer for the suggestion.

llvm-svn: 286462
2016-11-10 15:41:34 +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 e93e0adbb5 Reverted r286451 "[ELF] - Allow separate form for -f (alias for -auxiliary)."
Though the patch was technically correct,
the only FreeBSD port (noticed atm) that tried using it was
www/mod_jk. And it seems just passed gcc option to linker by mistake:

"-Wl,-L-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,-fstack-protector -Wl,-fstack-protector -o mod_jk.la "

Given that it is an easy mistake to make, reverting for now.

llvm-svn: 286458
2016-11-10 14:48:39 +00:00
George Rimar f5a0ef97f5 [ELF] - Allow separate form for -f (alias for -auxiliary).
Without that FreeBSD port was failing with next confuxing error:
/usr/bin/ld: error: unknown argument: -fstack-protector

llvm-svn: 286451
2016-11-10 14:07:15 +00:00
Eugene Leviant 12e8a92acd [ELF] Make SyntheticSection::writeTo pure virtual. NFC.
llvm-svn: 286445
2016-11-10 12:50:59 +00:00
Eugene Leviant 41ca327b5e [ELF] Convert .got.plt section to input section
Differential revision: https://reviews.llvm.org/D26349

llvm-svn: 286443
2016-11-10 09:48:29 +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
Rui Ueyama 35e007515f Add comment and simplify code a bit. NFC.
llvm-svn: 286422
2016-11-10 00:12:28 +00:00
Rui Ueyama 1bdaf3e30c Remove an overloaded function to simplify.
This version of addRegular is almost identical to the other except
it lacked "size" parameter.

llvm-svn: 286416
2016-11-09 23:37:40 +00:00
Rafael Espindola e08e78df6d Make OutputSectionBase a class instead of class template.
The disadvantage is that we use uint64_t instad of uint32_t for some
value in 32 bit files. The advantage is a substantially simpler code,
faster builds and less code duplication.

llvm-svn: 286414
2016-11-09 23:23:45 +00:00
Rui Ueyama 58026af7f0 Simplify parseEmulation. NFC.
llvm-svn: 286406
2016-11-09 22:32:43 +00:00
Rui Ueyama df5d14d6e7 Split OutputSection ctor. NFC.
llvm-svn: 286405
2016-11-09 22:32:42 +00:00
Simon Atanasyan 93214b7018 [ELF][MIPS] Attempt to fix buildbot
llvm-svn: 286401
2016-11-09 21:46:42 +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
Rafael Espindola 6ff570a395 Make Discarded a InputSection.
It was quite confusing that it had SectionKind of Regular, but was not
actually a InputSection.

llvm-svn: 286379
2016-11-09 16:55:07 +00:00
George Rimar 470de71177 [ELF] - Add separate form for -R alias.
During link of devel/chrpath (FreeBSD port), found next issue:
/usr/bin/ld: error: unclosed comment in a linker script
/usr/bin/ld: error: line 1: unknown directive: �
/usr/bin/ld: error: ��

Problem was not obvious and the reason was that we did not accept
the separate form of -R. While invocation line contained it:
cc -Wl,-R /usr/local/lib -o prog prog.c

CPIO file produced contained /usr/local/lib file. 
Which looks because of reasons above
contained inside the content of whole lib folder, 
and it then was passed as an input and
proccessed as linker script.

llvm-svn: 286378
2016-11-09 16:38:15 +00:00
Rafael Espindola 77dbe9a405 Add a convenience getObj method. NFC.
llvm-svn: 286370
2016-11-09 14:39:20 +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
George Rimar 25143dfd48 [ELF] - Ignore -stats command line option.
llvm-svn: 286348
2016-11-09 08:59:59 +00:00
Rafael Espindola 04a2e348bb Split Header into individual fields.
This is similar to what was done for InputSection.

With this the various fields are stored in host order and only
converted to target order when writing.

llvm-svn: 286327
2016-11-09 01:42:41 +00:00
Rui Ueyama edc183e437 Simplify getLocation() function.
All tests pass without the first parameter, so I guess we don't need it.

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

llvm-svn: 286287
2016-11-08 20:30:19 +00:00