Commit Graph

7820 Commits

Author SHA1 Message Date
Bob Haarman b96b10102a [COFF] support /ERRORLIMIT option
Summary: This adds support for reporting multiple errors in a single invocation of lld-link. The limit defaults to 20 and can be changed with the /ERRORLIMIT command line parameter, or set to unlimited by passing a value of 0.

Reviewers: pcc, ruiu

Reviewed By: ruiu

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

llvm-svn: 295507
2017-02-17 22:46:06 +00:00
George Rimar 858a659a4f [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs
Previously LLD crashed on on provided testcases because "/DISCARD/" was
not supported. Patch implements that.

After this I think there is no known issues with --emit-relocs implementation
required for linux kernel linking.

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

llvm-svn: 295488
2017-02-17 19:46:47 +00:00
Rafael Espindola 3773bcac55 Fix --print-gc-sections with linker scripts.
Before it would never print anything.

Thanks to George Rimar for pointing it out.

llvm-svn: 295485
2017-02-17 19:37:30 +00:00
George Rimar 647c1685b6 [ELF] - Move DependentSections vector from InputSection to InputSectionBase
I splitted it from D29273.
Since we plan to make relocatable sections as dependent for target ones for
--emit-relocs implementation, this change is required to support .eh_frame case.

EhInputSection inherets from InputSectionBase and not from InputSection.
So for case when it has relocation section, it should be able to access DependentSections
vector.

This case is real for Linux kernel.

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

llvm-svn: 295483
2017-02-17 19:34:05 +00:00
Rafael Espindola ecbfd871f9 Don't print DISCARD sections as gced.
This is a small difference I noticed to gold and bfd. When given
--print-gc-sections, we print sections a linkerscript marks
DISCARD. The other linkers don't.

llvm-svn: 295467
2017-02-17 17:35:07 +00:00
Rafael Espindola 679828ff92 Diagnose another case of the location counter moving backwards.
This case should be possible to handle, but it is hard:

* In order to create program headers correctly, we have to scan the
  sections in the order they are in the file.

* To find that order, we have to "execute" the linker script.

* The linker script can contain SIZEOF_HEADERS.

So to support this we have to start with a guess of how many headers
we need (3), run the linker script and try to create the program
headers. If it turns out we need more headers, we run the script again
with a larger SIZEOF_HEADERS.

Also, running the linker script depends on knowing the size of the
sections, so we have to finalize them. But creating the program
headers can change the value stored in some sections, so we have to
split size finalization and content finalization.

Looks like the last part is also needed for range extension thunks, so
we might support this at some point. For now just report an error
instead of producing broken files.

llvm-svn: 295458
2017-02-17 16:26:13 +00:00
Rafael Espindola 4cd7352c4f Reject moving the location counter backwards.
We were only checking when the assignment was inside a section.

llvm-svn: 295454
2017-02-17 16:01:51 +00:00
Rafael Espindola 1a5c152b9c Add static. NFC.
llvm-svn: 295448
2017-02-17 14:32:15 +00:00
Rui Ueyama 85c2201fc1 Rename getAliases -> getSymbolsAt.
The previous name caused a little confusion because the function not
only returns aliases but a given symbol itself too.

llvm-svn: 295408
2017-02-17 03:34:17 +00:00
Rui Ueyama 5acac350e7 Add a comment.
llvm-svn: 295388
2017-02-17 00:40:44 +00:00
Rafael Espindola ee61d3589f Merge reloc sections in -emit-reloc mode.
Without this we would produce two relocation sections pointing to the
same section, which gnu tools reject.

This fixes pr31986.

The implementation of -r/--emit-reloc is getting fairly
complicated. But lets get the test passing before trying to refactor
it.

llvm-svn: 295385
2017-02-17 00:28:17 +00:00
Zachary Turner 7b327d051b [pdb] Add the ability to resolve TypeServer PDBs.
Some PDBs or object files can contain references to other PDBs
where the real type information lives.  When this happens,
all type indices in the original PDB are meaningless because
their records are not there.

With this patch we add the ability to pull type info from those
secondary PDBs.

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

llvm-svn: 295382
2017-02-16 23:35:45 +00:00
Rafael Espindola 6386628aae Move specialization to try to fix the bots.
I cannot reproduce the issue locally, but for some reason some bots
want to instantiate this from the header.

llvm-svn: 295365
2017-02-16 19:23:15 +00:00
Rafael Espindola 8290274c13 Share more output section creation code.
We can do this now that the linker script and the writer agree on
which sections should be combined.

llvm-svn: 295341
2017-02-16 17:32:26 +00:00
George Rimar 505ac8dc41 [ELF] - Do not crash when discarding sections that are referenced by others.
SHF_LINK_ORDER sections adds special ordering requirements.
Such sections references other sections. Previously we would crash
if section that other were referenced to was discarded by script.

Patch fixes that by discarding all dependent sections in that case.
It supports chained dependencies, testcase is provided.

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

llvm-svn: 295332
2017-02-16 16:06:13 +00:00
Rafael Espindola 908a3d3420 Ignore relocation sections in linker scripts.
Unfortunately, the common way of writing linker scripts seems to be
to get the output of ld.bfd --verbose and edit it a bit.

Also unfortunately, the bfd default script contains things like

.rela.dyn : { *(... .rela.data ...) }

but bfd actually ignores that for -emit-relocs, so we have to do the
same.

llvm-svn: 295324
2017-02-16 14:36:09 +00:00
Rafael Espindola 82f00ec4a2 Fix crash with -emit-relocs -shared.
The code to handle the input SHT_REL/SHT_RELA sections was getting
confused with the linker generated relocation sections.

llvm-svn: 295322
2017-02-16 14:23:43 +00:00
George Rimar 09015fee3c [ELF] - Allow section to have multiple dependent sections.
That fixes a case when section has more than one metadata 
section. Previously GC would collect one of such sections 
because we had implementation that stored only last one as
dependent.

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

llvm-svn: 295298
2017-02-16 08:41:19 +00:00
Rui Ueyama cd19b039ce Use isRelExprOneOf.
llvm-svn: 295289
2017-02-16 06:24:16 +00:00
Rui Ueyama f829e8c97d Removes a trivial accessor.
llvm-svn: 295288
2017-02-16 06:12:41 +00:00
Rui Ueyama 924b361d01 Do not overload a one-bit variable, NeedsCopyOrPltAddr.
This patch removes NeedsCopyOrPltAddr and instead add two variables,
NeedsCopy and NeedsPltAddr. This uses one more bit in Symbol class,
but the actual size doesn't increase because we had unused bits.
This should improve code readability.

llvm-svn: 295287
2017-02-16 06:12:22 +00:00
Rui Ueyama 26ad057099 Add comments.
llvm-svn: 295283
2017-02-16 04:51:46 +00:00
Rui Ueyama 750c11c099 Split a function and add comments.
This is slightly inefficient than the previous code, but that is really
negligible as this function is usually called at most only a few times.

llvm-svn: 295282
2017-02-16 04:39:45 +00:00
Rui Ueyama dec4ab0d0d Add comments.
llvm-svn: 295280
2017-02-16 04:19:03 +00:00
Rui Ueyama da5cc84661 Add CopyRelSection instances to BSS in the regular way.
Previously, space in a BSS section for copy relocations are reserved
in a special way. We directly manipulated size of the BSS section.
r294577 changed the way of doing it. Now, we create an instance of
CopyRelSection (which is a synthetic input section) for each copy
relocation.

This patch removes the remains of the old way and add CopyRelSections
to BSS sections using `addSections` function, which is the usual
way to add an input section to an output section.

llvm-svn: 295278
2017-02-16 04:12:19 +00:00
Rafael Espindola 7386ceac74 Addends should always be signed.
In the target dependent code we already always return a int64_t. In
the target independent code we carefully use uintX_t, which has the
same result given 2 complement rules.

This just simplifies the code to use int64_t everywhere.

llvm-svn: 295263
2017-02-16 00:12:34 +00:00
Ed Schouten 3bf713043a Make --export-dynamic work on non-PIC/PIE targets.
For CloudABI I'm only interested in generating non-PIC/PIE executables
on armv6 and i686, as PIE introduces larger overhead than on aarch64 and
x86_64. Still, I want to be able to instruct the linker to generate a
dynamic symbol table if requested. One example use for this is that
dynamic symbol tables can be used by programs to print nicely formatted
stacktraces, including symbol names.

Right now there seems to be some logic in LLD that it only wants to emit
dynamic symbol tables when either linking against libraries or when
building PIC. Let's extend this to also take --export-dynamic into
account.

Reviewed by:	ruiu
Differential Revision:	https://reviews.llvm.org/D29982

llvm-svn: 295240
2017-02-15 21:51:25 +00:00
Rui Ueyama 731a66ae98 Apply different tokenization rules to linker script expressions.
The linker script lexer is context-sensitive. In the regular context,
arithmetic operator characters are regular characters, but in the
expression context, they are independent tokens. This afects how the
lexer tokenizes "3*4", for example. (This kind of expression is real;
the Linux kernel uses it.)

This patch defines function `maybeSplitExpr`. This function splits the
current token into multiple expression tokens if the lexer is in the
expression context.

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

llvm-svn: 295225
2017-02-15 19:58:17 +00:00
Rui Ueyama a4601b5d7a Simplify operator tests.
llvm-svn: 295222
2017-02-15 19:36:01 +00:00
Rui Ueyama fd5edff8d6 Rename a test as they are tests for operators.
llvm-svn: 295221
2017-02-15 19:35:41 +00:00
George Rimar 2c29b40360 [ELF] - Fix relocation-group.test
Main intention of test was to check that 
we do not crash, but for additional check
it previously run readobj for input object
instead of output.

llvm-svn: 295161
2017-02-15 09:44:12 +00:00
Simon Atanasyan 91e30ae205 [ELF][MIPS] Fix writing updated addend for R_MIPS_GOT16 relocation
If target of R_MIPS_GOT16 relocation is a local symbol its addend
is high 16 bits of complete addend. To calculate a final value, the addend
of this relocation is read, shifted to the left and combined with addend
of paired R_MIPS_LO16 relocation. To save updated addend when the linker
produces a relocatable output, we need to store high 16 bits of the
addend's value. It is different from the case of writing the relocation
result when the linker saves a 16-bit GOT index as-is.

llvm-svn: 295159
2017-02-15 08:33:03 +00:00
Rafael Espindola d50c8598fb Set the correct r_offset even when creating a R_*_NONE.
With this lld can use its own -r output when a fde is discarded.

llvm-svn: 295143
2017-02-15 01:53:23 +00:00
Rafael Espindola f340ca8963 Make lld able to handle gold's -r output.
This is still not sufficient for lld to handle its own output when a
fde points to a discarded section. I am investigating if it is better
to change the -r output or make lld able to read the current version.

llvm-svn: 295141
2017-02-15 01:29:23 +00:00
Rafael Espindola 60b02509dd Handle .eh_frame pointing to discarded section in -r.
This is a really horrible case. If a .eh_frame points to a discarded
section, it is not clear what is the correct thing to do.

It looks like ld.bfd discards the entire .eh_frame content and gold
discards the second relocation, leaving one frame with an fde that
refers to a bogus location. This is similar to what gold does.

llvm-svn: 295133
2017-02-15 00:59:50 +00:00
Rafael Espindola a8541675e0 Revert "Relax the restriction on what relocations can be in a non-alloc section."
This reverts commit r295102.

In the link of seabios the assumption seems to be that the section has
an actual address, so this is not sufficient. Changing the assembly
code to add a "a" flag seems like the correct thing to do instead of
extending this hack.

Sorry about the noise.

Original message:

    Relax the restriction on what relocations can be in a non-alloc section.

    The main thing that they can't have is relocations that require the
    creation of gots or plt.  For now also accept R_PC.

    Found while linking seabios.

llvm-svn: 295130
2017-02-15 00:27:47 +00:00
Rafael Espindola 1b36eeaafa Fix the st_name of section symbols.
If it is non-zero then objdump will print an empty name when printing
relocations against the section.

llvm-svn: 295129
2017-02-15 00:23:09 +00:00
Rui Ueyama 35723f09bb Explicitly return a new value instead of implicitly mutating a reference.
I think this is more readable than before.

llvm-svn: 295121
2017-02-14 23:35:42 +00:00
Rafael Espindola ee29e42b33 Relax the restriction on what relocations can be in a non-alloc section.
The main thing that they can't have is relocations that require the
creation of gots or plt.  For now also accept R_PC.

Found while linking seabios.

llvm-svn: 295102
2017-02-14 20:14:03 +00:00
Rui Ueyama f9a45628a3 Remove stray semicolon.
llvm-svn: 295077
2017-02-14 17:36:23 +00:00
George Rimar ee6f22ce0b [ELF] - Do not segfault when using -r and section groups.
If we had SHT_GROUP sections, then when -r was used we might crash.
This is PR31952.

Issue happened because we emited relocation section though its target was discared
because was a member of duplicated group. When we tried to get VA of target,
segfault happened.
Core cause is the bug that GNU as 2.27 (and probably later versions) has.
In compare with llvm-mc, it does not include relocation sections into the group, 
like shown in testcase. This patch covers that case.

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

llvm-svn: 295067
2017-02-14 16:42:38 +00:00
Rafael Espindola 17ba44519b Sign extend remaining implicit addends for consistency.
llvm-svn: 295062
2017-02-14 16:24:42 +00:00
George Rimar bdce4ad21d [ELF] - Do sign extend for addends of R_386_8, R_386_16 relocations
Patch makes addends for addends of R_386_8, R_386_16 relocations
be sign extended.

The same we did earlier for PC ones,
currenly LLD fails to link linux kernel, 
reporting relocation out of range because of this.

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

llvm-svn: 295052
2017-02-14 13:22:03 +00:00
Simon Atanasyan 7a2a1ff37f [ELF][MIPS] Use `InputSectionBase::getOutputSection()` to access output sections from the `MipsGotSection`
Follow-up to r294005. This patch restores handling of MISP GOT
relocations against merge sections.

llvm-svn: 295040
2017-02-14 09:56:16 +00:00
Rui Ueyama 104e2357de Do not store a computable attributes to Config.
llvm-svn: 295031
2017-02-14 05:45:47 +00:00
Rui Ueyama 4c82b4f6fa Add file comments for ScriptParser.cpp.
llvm-svn: 295023
2017-02-14 04:47:24 +00:00
Rui Ueyama 794366a237 Rename ScriptParser.{cpp,h} -> ScriptLexer.{cpp,h}.
These files contain a lexer, so the new names are better.
The parser is in LinkerScript.{cpp,h}.

llvm-svn: 295022
2017-02-14 04:47:05 +00:00
Rafael Espindola 195fba2967 Fix checks for R_386_8 and R_386_16.
Results created by these relocations are expected to be zero extended
at runtime.

llvm-svn: 294988
2017-02-13 21:29:56 +00:00
Peter Collingbourne 904c5ed558 ELF: Read all dynamic lists specified on the command line.
We were previously only reading the last one.

Fixes PR31939 (which was likely the issue underlying
https://github.com/google/oss-fuzz/issues/295).

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

llvm-svn: 294977
2017-02-13 18:31:12 +00:00
Davide Italiano db4b0a7194 [LTO] Add support for optimization remarks.
Differential Revision:  https://reviews.llvm.org/D29878

llvm-svn: 294971
2017-02-13 17:49:18 +00:00