Commit Graph

4820 Commits

Author SHA1 Message Date
Rui Ueyama 5aa2db1e12 Initialize a member in C++11 style. NFC.
llvm-svn: 326933
2018-03-07 19:25:27 +00:00
George Rimar bf3c384673 [ELF] - Adjust rangeToString to report ranges in a different format.
It was raised during the review of D43819.

LLD usually use [X, Y] for reporting ranges, like below:
"relocation R_386_16 out of range: 65536 is not in [0, 65535]"

Patch changes rangeToString() to do the same.

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

llvm-svn: 326918
2018-03-07 17:54:25 +00:00
Rui Ueyama b0084a0eee Revert r326911: Improve --warn-symbol-ordering.
This reverts commit r326911 because it was committed by accident.

llvm-svn: 326914
2018-03-07 17:24:46 +00:00
Rui Ueyama e1847da924 Rename Indent{1,2} -> Indent{8,16}.
llvm-svn: 326912
2018-03-07 17:15:15 +00:00
Rui Ueyama ebfab927d9 Improve --warn-symbol-ordering.
Summary:
I originally tried to simplify code and then noticed that lld doesn't
do what it tells to the user by warn(). It says "unable to order
discarded symbol" but it actually can for sections eliminated by ICF.
With this patch, lld doesn't sort such sections.

Reviewers: jhenderson, rafael

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 326911
2018-03-07 17:15:06 +00:00
James Henderson cb4c19f315 [ELF] Prevent crash when reporting errors if debug line cannot be parsed
LLD uses the debug info and debug line sections to determine the location of
e.g. references to undefined symbols, when producing error messages. In the
event that debug info was present, but debug line parsing failed for some
reason, then a nullptr would end up being dereferenced by the location-lookup
code.

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

Reviewers: grimar
llvm-svn: 326899
2018-03-07 15:22:58 +00:00
George Rimar 527bfd7a48 [ELF] - Recommit r326892,r326893 "[ELF] - Report LMA region overflows."
With fix: add missing "RUN:" prefix to test case.

Original commit message:
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.

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

llvm-svn: 326895
2018-03-07 12:44:18 +00:00
George Rimar 06846c2251 [ELF] - Revert r326892, r326893.
Bots are still unhappy:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/26259

llvm-svn: 326894
2018-03-07 12:33:00 +00:00
George Rimar 97e054e00d [ELF] - Report LMA region overflows.
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.

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

llvm-svn: 326892
2018-03-07 11:54:30 +00:00
George Rimar 54baa5f45f [ELF] - Allow discarding .hash and .gnu.hash from linker script.
Currently, LLD segfaults when linker script attempts to discard
one of the hash sections. This patch fixes that.

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

llvm-svn: 326891
2018-03-07 11:47:15 +00:00
Rui Ueyama 9e0171fbb6 Do not create temporary strings just to print out spaces. NFC.
llvm-svn: 326841
2018-03-06 22:48:46 +00:00
Rui Ueyama 09fcd4c34c Implement --just-symbols.
Differential Revision: https://reviews.llvm.org/D39348

llvm-svn: 326835
2018-03-06 21:25:37 +00:00
Rafael Espindola ddb33c0961 Improve duplicated version handling.
It looks like the problem that caused us to originally warn instead of
error was that of a symbol being assigned to the same version twice.

Now we don't warn if a symbol is assigned to the same version twice,
but error if it is assigned to multiple.

This fixes pr28342.

llvm-svn: 326813
2018-03-06 17:05:12 +00:00
Rui Ueyama 067617f9ba Remove redundant casts.
llvm-svn: 326753
2018-03-05 23:50:45 +00:00
George Rimar 162d436c8e [ELF] - Support moving location counter when MEMORY is used.
We do not expand memory region correctly for following scripts:

.foo.1 : 
 {
   *(.foo.1)
   . += 0x1000;
 } > ram
Patch generalizes expanding of output sections and memory
regions in one place and fixes the issue.

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

llvm-svn: 326688
2018-03-05 10:54:03 +00:00
George Rimar 7b91e2133e [ELF] - Report location for div/mod by zero.
"division by zero" or "modulo by zero" are not
very informative errors and even probably confusing
as does not let to know that error is coming from linker script.
Patch adds location reporting.

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

llvm-svn: 326686
2018-03-05 10:02:44 +00:00
Rafael Espindola e3a6062844 Simplify. NFC.
Since r321982 we don't set VersionId in scanShlibUndefined, which
makes InVersionScript redundant.

llvm-svn: 326641
2018-03-03 02:13:50 +00:00
George Rimar 97785af464 [ELF] - Report error when memory region is overflowed by data commands.
LLD can not catch a memory area overflow when using a data command.
If we have the script below:

.foo : 
{
  *(.foo)
  BYTE(0x1)
} > ram

where BYTE overflows the ram region, we do not report it currently.
Patch fixes that.

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

llvm-svn: 326545
2018-03-02 08:11:58 +00:00
Rui Ueyama 036ed36f0a Accept both `--foo bar` and `--foo=bar` styles options.
GNU linkers by convention supports both `--foo bar` and `--foo=bar` styles
for all long options that take arguments.

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

llvm-svn: 326506
2018-03-01 23:06:10 +00:00
Rui Ueyama 7c18abf99a Set DF_TEXTREL to executables that need text relocations.
Summary:
If an executable needs text relocations, it should be marked as such so
that the loader can prepare for text relocations. We currently create a
dummy segment with DT_TEXTREL for that purpose.

Generic ABI as of 2000 [1] mentioned that "Its [DT_TEXTREL's] use
has been superseded by the DF_TEXTREL flag". However, it's actually not
superseded even after 18 years. OpenBSD and musl recognize only DT_TEXTREL.
So we still need to set both.

[1] http://www.sco.com/developers/gabi/2000-07-17/ch5.dynamic.html

Reviewers: rafael

Subscribers: emaste, llvm-commits, arichardson

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

llvm-svn: 326503
2018-03-01 22:56:52 +00:00
Rafael Espindola 2e4bcb0095 Don't ingoned --enable-new-dtags.
llvm-svn: 326498
2018-03-01 22:23:51 +00:00
Rafael Espindola e75b42ee4e Don't allocate a header bellow address 0.
With the current code if the script has a PHDRS we always obey and try
to allocate a header. This can cause Min - HeaderSize to underflow.

It looks like bfd actually prints an error for this case. With this
patch we do the same.

Found while looking at pr36515.

llvm-svn: 326441
2018-03-01 15:25:46 +00:00
George Rimar b068b03793 [ELF] - Don't crash on broken MEMORY declaration.
LLD crashes with broken scripts shown in testcase,
because fails to read memory regon name and accesses
MemoryRegions's element which is nullptr.
Patch fixes it.

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

llvm-svn: 326431
2018-03-01 12:36:01 +00:00
George Rimar c4df670dea [ELF] - Do not remove empty sections that use symbols in expressions.
This is PR36515.

Currenly if we have a script like .debug_info 0 : { *(.debug_info) },
we would not remove this section and keep it in the output.
That does not work, because it is common case for
debug sections to have a zero address expression.
Patch changes behavior so that we remove only sections
that do not use symbols in its expressions.

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

llvm-svn: 326430
2018-03-01 12:27:04 +00:00
Rui Ueyama 37ad8161e4 Do not create multiple NOTE segments.
Previously, we didn't try to make effort to put .note sections next
to each other in the output file, so two .note sections were likely
to be stored to two separate NOTE segments. That's undesirable because
we should create as few segments as possible in general.

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

llvm-svn: 326410
2018-03-01 02:31:29 +00:00
Rafael Espindola 852bd5c062 Simplify removing empty output sections.
With this the meaning of the Live bit in output sections is clear: we
have at some point added a input section into it.

llvm-svn: 326401
2018-03-01 01:08:00 +00:00
Rui Ueyama 39ba31ff50 Add "%" operator to the linker script.
This patch improves compatibility with GNU linkers.

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

llvm-svn: 326348
2018-02-28 18:38:13 +00:00
Rui Ueyama 1d20222a48 Inline a trivial function. NFC.
llvm-svn: 326347
2018-02-28 18:25:00 +00:00
Rafael Espindola 367bfce611 Simplify. NFC.
llvm-svn: 326344
2018-02-28 18:05:37 +00:00
Rui Ueyama ee17371897 Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.

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

llvm-svn: 326339
2018-02-28 17:38:19 +00:00
Igor Kudrin c844524e46 [ELF] Process linker scripts deeper when declaring symbols.
We should process symbols inside output section declarations the same way as top-level ones.

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

llvm-svn: 326305
2018-02-28 05:55:56 +00:00
Rui Ueyama f0884e474c Add `--dynamic-linker=foo` as an alias for `--dynamic-linker foo`.
This patch fixes a minor compatibility issue with ld.gold and ld.bfd.

llvm-svn: 326243
2018-02-27 20:37:18 +00:00
Rafael Espindola 3f4c673d38 Put undefined symbols from shared libraries in the symbol table.
With the recent fixes these symbols have more in common than not with
regular undefined symbols.

llvm-svn: 326242
2018-02-27 20:31:22 +00:00
Rafael Espindola b851121130 Fix gcc warning.
Should fix the build in some bots.

llvm-svn: 326209
2018-02-27 17:11:10 +00:00
Rafael Espindola 3bfa8f0120 Add support for SHF_ARM_PURECODE.
Now we don't mark a PT_LOAD as readable if all its sections are
SHF_ARM_PURECODE.

llvm-svn: 326207
2018-02-27 16:55:25 +00:00
George Rimar 46045364b2 [ELF] - Format, fix mistype. NFC.
llvm-svn: 326198
2018-02-27 14:06:47 +00:00
George Rimar a77b963c90 [ELF] - Fix case of using both --icf and --symbol-ordering-file together.
Imagine that we have sections A, B, C, where A == C and
symbol ordering file containing symbols: symC, symB, symA

Previously because of ICF it was possible that final order would be
B, A or B, C. That violates order specified in ordering file.
Patch changes that.

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

llvm-svn: 326179
2018-02-27 08:26:38 +00:00
Igor Kudrin 3345c9ac18 [ELF] Create and export symbols provided by a linker script if they referenced by DSOs.
It should be possible to resolve undefined symbols in dynamic libraries
using symbols defined in a linker script.

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

llvm-svn: 326176
2018-02-27 07:18:07 +00:00
Rafael Espindola 79c23eec04 Keep flags from phantom synthetic sections.
This fixes pr36475.

I think this code can be simplified a bit, but I would like to check
in the more direct fix if we are in agreement on the direction and
then refactor.

This is not something that bfd does. The issue is not noticed in bfd
because it keeps fewer sections from the linkerscript in the output.

The reasons why it seems reasonable to do this:

- As George noticed, we would still keep the flags if the output
  section had both an empty synthetic section and a regular section
- We need an heuristic to find the flags of output sections. Using the
  flags of a synthetic section that would have been there seems a
  reasonable heuristic.

llvm-svn: 326137
2018-02-26 22:32:15 +00:00
George Rimar 0c97f4eba4 [ELF] - Fix variable name and mistype in comment. NFC.
llvm-svn: 326090
2018-02-26 15:16:03 +00:00
Fangrui Song ffac3ed341 [ELF] Fix IsPreemptible comment and typo. NFC
llvm-svn: 325963
2018-02-23 21:57:49 +00:00
Simon Atanasyan a4cde9d2e2 [ELF][MIPS] Set EI_ABIVERSION flag accordingly to MIPS ABIs requirement
MIPS ABIs require that if an executable file uses non-PIC model, the
EI_ABIVERSION entry in the ELF header should be incremented from 0 to 1.
That allows obsoleted / limited dynamic linkers refuse to link them.

llvm-svn: 325890
2018-02-23 11:28:57 +00:00
George Rimar db1a062447 [ELF] - Do not remove empty output sections that are explicitly assigned to phdr in script.
This continues direction started in D43069.

We can keep sections that are explicitly assigned to segment in script.
It helps to simplify code.

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

llvm-svn: 325887
2018-02-23 10:53:04 +00:00
George Rimar 2d53967b48 Recommit "[ELF] - Do not crash with --emit-relocs and --icf=all together."
Latest patch version now.

Original commit message:

[ELF] - Do not crash with --emit-relocs and --icf=all together.

Previously we would crash because did not mark .rel[a] sections
as dead and they tried to access parent which was not live
after ICF and therefore was null.

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

llvm-svn: 325879
2018-02-23 10:37:33 +00:00
George Rimar aa359f87e8 [ELF] - Revert r325877 "[ELF] - Do not crash with --emit-relocs and --icf=all together."
Not latest version of patch was committed by mistake.

llvm-svn: 325878
2018-02-23 10:30:31 +00:00
George Rimar cde84d1cd0 [ELF] - Do not crash with --emit-relocs and --icf=all together.
Previously we would crash because did not mark .rel[a] sections
as dead and they tried to access parent which was not live
after ICF and therefore was null.

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

llvm-svn: 325877
2018-02-23 10:27:13 +00:00
George Rimar 3cdf0d969a [ELF] - Report error if removed empty output section declaration used undefined symbols.
This is for fixing PR36297.

Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } };
script and no section .stub, when LLD will remove .bar, but
produce output with undefined symbols a and b.

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

llvm-svn: 325875
2018-02-23 10:15:54 +00:00
Fangrui Song 9cd5df0e15 [ELF] Add comment for preemptible and fix typo. NFC
Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 325855
2018-02-23 02:05:48 +00:00
Rui Ueyama c30927411c Make undefined symbol in DSO to pull out object files from archive files.
We have an internal program that does't link without this patch. I don't
know of any open-source program that needs this, but there might be.
Since this patch improves compatibility with GNU linkers with a few lines
of code, I think it's worth to be committed.

The problem is about undefined symbols in DSOs. Some programs depend on
the GNU linkers' behavior that they pull out object files from archive
files to resolve undefined symbols in DSOs. We already allow that kind of
"reverse" dependency (from DSOs to the main executable) for regular
symbols, in particular, for "__progname" symbol (which is usually in
crt0.o), but that doesn't work if the symbol is in an archive file.
This patch is to make it work.

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

llvm-svn: 325849
2018-02-23 01:16:57 +00:00
George Rimar 925529b821 [ELF] - Rewrote outdated comment. NFC.
llvm-svn: 325809
2018-02-22 17:52:43 +00:00