Commit Graph

2963 Commits

Author SHA1 Message Date
Simon Pilgrim bb643ab5bc Attempt to fix windows buildbot
llvm-svn: 291348
2017-01-07 15:44:27 +00:00
Rafael Espindola 2756e04fac Handle versioned undefined symbols.
In order to keep symbol lookup a simple name lookup this patch adds
versioned symbols with an explicit @ to the symbol table.

llvm-svn: 291293
2017-01-06 22:30:35 +00:00
Rafael Espindola 4b9610ba28 Fix test now that --reproduce takes a full filename.
llvm-svn: 291261
2017-01-06 18:55:37 +00:00
Reid Kleckner 3d3245fd83 Match backslashes in undef.s test on Windows
llvm-svn: 291257
2017-01-06 18:23:30 +00:00
Rui Ueyama 0b3b813172 Attempt to unbreak buildbots.
llvm-svn: 291212
2017-01-06 02:54:38 +00:00
Rui Ueyama 7f1f912794 Use TarWriter to create tar archives instead of cpio.
This is how we use TarWriter in LLD. Now LLD does not append
a file extension, so you need to pass `--reproduce foo.tar`
instead of `--reproduce foo`.

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

llvm-svn: 291210
2017-01-06 02:33:53 +00:00
Rafael Espindola 337139830e Change which input sections we concatenate
After Mark's patch I was wondering what was the rationale for the ELF
spec requiring us to merge only sections with matching flags and
types. I tried emailing
https://groups.google.com/forum/#!forum/generic-abi, but looks like my
emails are not being posted (the list is probably moderated). I
emailed Cary Coutant instead.

Cary pointed out that the section was a late addition and didn't got
the scrutiny it deserved. Given that and the problems found by
implementing the letter of the standard, I propose changing lld to
merge all sections with the same name and issue errors if the types or
some critical flags are different.

This should allow an unmodified firefox linked with lld to run.

This also merges some code with the linkerscript path.

llvm-svn: 291107
2017-01-05 14:20:35 +00:00
Rafael Espindola 64cc2a0f18 Delete stale test.
We no longer tail merge section names.

llvm-svn: 290988
2017-01-04 19:14:34 +00:00
Peter Collingbourne 7b5088b3b2 ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.
The glibc dynamic loader rounds the size down, so without this the loader
will fail to change the memory protection for the last page.

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

llvm-svn: 290986
2017-01-04 18:56:15 +00:00
Saleem Abdulrasool 8d29e62de7 test: loosen a test for the time being
The GUID should match between the RSDS and the PDB.  This should repair
the build bots, though we should be ensuring that the GUIDs match.
Unfortunately, different build bots seem to be getting different GUIDs.

llvm-svn: 290981
2017-01-04 18:17:28 +00:00
Saleem Abdulrasool df8a13b257 COFF: tie the execute and the PDB together
The PDB GUID, Age, and version are tied together by the RSDS record in
the binary.  Pass along the BuildId information into the createPDB to
allow us to tie the binary and the PDB together.

llvm-svn: 290975
2017-01-04 17:56:54 +00:00
Peter Smith 97c6d78f3e [ELF] Add support for thunks to undefined non-weak symbols
In a shared library an undefined symbol is implicitly imported. If the
symbol is called as a function a PLT entry is generated for it. When the
caller is a Thumb b.w a thunk to the PLT entry is needed as all PLT
entries are in ARM state.
    
This change allows undefined symbols to have thunks in the same way that
shared symbols may have thunks.

llvm-svn: 290951
2017-01-04 09:45:45 +00:00
Eugene Leviant f6aeed3624 [ELF] Linkerscript: print location of undefined symbol usage
Differential revision: https://reviews.llvm.org/D27194

llvm-svn: 290339
2016-12-22 13:13:12 +00:00
George Rimar f39cdea879 [ELF] - Use error() instead of fatal() during relaxation of R_X86_64_GOTTPOFF
This is last known noticable fatal() in target.cpp.
We also have other ones for unknown relocations or
creating unknown targets, but that one can be just error I think.

Used yaml2obj to generate test.

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

llvm-svn: 290335
2016-12-22 11:05:05 +00:00
Rui Ueyama 8781c425b3 Make -color-diagnostics an alias to -color-diagnostics=always.
Previously, that was an alias to -color-diagnostics=auto. However,
Clang's -fcolor-diagnostics is an alias to -fcolor-diagnostics=always,
so that was confusing. This patch fixes that issue.

llvm-svn: 290332
2016-12-22 08:20:28 +00:00
Davide Italiano 7116dc908c [ELF/tests] Use cpio -it instead of cpio -t.
OpenBSD's cpio does not accept the -t option without -i.
Apparently some systems implement cpio -t as a shortcut
for cpio -it, the latter is the only thing that's documented.
This change avoids test failures on OpenBSD.

Patch by Mark Kettenis!

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

llvm-svn: 290252
2016-12-21 12:22:19 +00:00
George Rimar d450065308 [ELF] - Linkerscript: Fall back to search paths when INCLUDE not found
From https://sourceware.org/binutils/docs/ld/File-Commands.html:
The file will be searched for in the current directory, and in any 
directory specified with the -L option.

Patch done by Alexander Richardson.

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

llvm-svn: 290247
2016-12-21 09:42:25 +00:00
George Rimar cc9302d0b7 [ELF] - Removed trailing whitespaces. NFC.
llvm-svn: 290243
2016-12-21 08:58:36 +00:00
George Rimar dcf5b72e20 [ELF] - Do not call fatal() in Target.cpp, call error() instead.
We probably would want to avoid fatal() if we can in context of librarification,
but for me reason of that patch is to help D27900 go.

D27900 changes errors reporting to something like
error: text1
note: text2
note: text3

where hint used to provide additional information about location. In that case
I can't just call fatal() because user will not see notes after that what adds additional complication to handle.
So It is good to switch fatal() to error() where it is possible.

Also it adds testcase with broken relocation number. 
Previously we did not have any, It checks that error() instead of fatal() works fine.

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

llvm-svn: 290239
2016-12-21 08:21:34 +00:00
Simon Atanasyan 86dc60d8d4 [ELF][MIPS] Allow .MIPS.abiflags larger than one Elf_Mips_ABIFlags struct
Older versions of BFD generate libraries with .MIPS.abiflags that only
concatenate the individual .MIPS.abiflags sections instead of merging.

Patch by Alexander Richardson.

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

llvm-svn: 290237
2016-12-21 05:31:57 +00:00
Simon Atanasyan 8f7d28122c [ELF] Do not warn about missed entry symbol in case of relocatable output
Relocatable file does not need to have an entry symbol so the warning is
useless in that case.

llvm-svn: 290206
2016-12-20 22:24:45 +00:00
George Rimar d003c7f394 [ELF] - Treat .openbsd.randomdata as relro section
That was requested by Mark Kettenis in llvm-dev:

"It is the intention that .openbsd.randomdata sections are made
read-only after initialization. The native (ld.bfd based) OpenBSD
toolchain accomplishes this by including .openbsd.randomdata into the
PT_GNU_RELRO segment."

He suggested code change, I added testcase.

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

llvm-svn: 290174
2016-12-20 11:28:54 +00:00
Rui Ueyama 0be9720875 Fix a bug that the glob pattern parser falls in an infinite loop for invalid patterns.
llvm-svn: 290160
2016-12-20 03:12:28 +00:00
Rui Ueyama 398f55f6f6 Set Config->ColorDiagnostics early so that all error messages are colored.
Previously, some errors that were checked before we set to
Config->ColorDiagnostics weren't colored. This patch moves the code
to set the variable so that such error messages are colored just like
other error messages.

llvm-svn: 290157
2016-12-20 02:17:24 +00:00
Rafael Espindola 5967c97323 Fix corner cases of setting the section address.
This handles all the corner cases if setting a section address:

- If the address is too low, we cannot allocate the program headers.
- If the load address is lowered, we have to do that before finalize

This also shares some code with the linker script since it was already
hitting similar cases.

This is used by the freebsd boot loader. It is not clear if we need to
support this with a non binary output, but it is not as bad as I was
expecting.

llvm-svn: 290136
2016-12-19 21:21:07 +00:00
George Rimar 2bb88ab5e0 [ELF] - Implemented --retain-symbols-file option
--retain-symbols-file=filename
Retain only the symbols listed in the file filename, discarding all others. 
filename is simply a flat file, with one symbol name per line. This option 
is especially useful in environments (such as VxWorks) where a large global 
symbol table is accumulated gradually, to conserve run-time memory.

Note: though documentation says "--retain-symbols-file does not discard 
undefined symbols, or symbols needed for relocations.", both bfd and gold 
do that, and this patch too, like testcase show.

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

llvm-svn: 290122
2016-12-19 18:00:52 +00:00
Adhemerval Zanella 86513f06be ELF/AArch64: Fix dynamic relocation against local symbol in shared objects
AArch64 TLSDESC for local symbol in shared objects are implemented in a
arch specific manner where the TLSDESC dynamic relocation addend is the
symbol VM inside the TLS block. For instance, with a shared library
created from the code:

--
static __thread int32_t x1;
static __thread int64_t x2;

int32_t foo1 (int32_t x)
{
  x1 += x;
  return x;
}

int64_t foo2 (int64_t x)
{
  x2 += x;
  return x;
}
--

The dynamic relocation should be create as:

Relocations [
  Section (N) .rela.dyn {
    <Address1> R_AARCH64_TLSDESC - 0x0
    <Address2> R_AARCH64_TLSDESC - 0x8
  }
]

Where 0x0 addend in first dynamic relocation is the address of 'x1'
in TLS block and '0x8' is the address of 'x2'.

Checked against test-suite on aarch64-linux-gnu.

llvm-svn: 290099
2016-12-19 11:58:01 +00:00
Rui Ueyama 5d804dc8f7 [ELF] - Linkerscript: Implement two argument version of ALIGN()
Fixes http://llvm.org/PR31129

Patch by Alexander Richardson!

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

llvm-svn: 289968
2016-12-16 18:19:35 +00:00
George Rimar b86448c669 [ELF] - Accept --sort-section=xxx command form.
--sort-section=xxx is the same as --sort-section xxx,
was found in one of FreeBSD ports.

llvm-svn: 289938
2016-12-16 11:59:52 +00:00
George Rimar 6cbfce7785 [ELF] - Make LLD accept Ttext-segment X/Ttext-segment=X aliases for -Ttext.
It os used in work/emulators/qemu-user-static port.
Which tries to use -Ttext-segment and then:

# In case ld does not support -Ttext-segment, edit the default linker
# script via sed to set the .text start addr.  This is needed on FreeBSD
# at least.
<here it calls -verbose to extract and edit default bfd linker script.>

Actually now we are do not fully support -Ttext properly (see D27613),
but we also seems never will provide anything close to default script, like bfd do,
so at least this patch introduces proper alias handling.

llvm-svn: 289827
2016-12-15 16:12:34 +00:00
George Rimar ec02b8d4c0 [ELF] - Partial support of --gdb-index command line option (Part 3).
Patch continues work started in D24706 and D25821.

in this patch symbol table and constant pool areas were
added to .gdb_index section output.

This one finishes the implementation of --gdb-index functionality in LLD.

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

llvm-svn: 289810
2016-12-15 12:07:53 +00:00
George Rimar 8b54739328 [ELF] - Partial support of --gdb-index command line option (Part 2).
Patch continues work started in D24706,

in this patch address area was added to .gdb_index section output.

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

llvm-svn: 289790
2016-12-15 09:08:13 +00:00
George Rimar 14460e0216 [ELF] - Do not crash when move location counter backward.
PR31335 shows that we do that in next case:
SECTIONS { .text 0x2000 : {. = 0x100 ; *(.text) } }

though documentations says that "If . is used inside a section 
description however, it refers to the byte offset from the start
of that section, not an absolute address. " looks does not work 
as documented in bfd (as mentioned in comments for PR31335).

Until we find out the expected behavior was suggested at least not
to 'crash', what we do after trying to generate huge file.

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

llvm-svn: 289782
2016-12-15 07:27:28 +00:00
Peter Collingbourne 6ee0b4e9f5 COFF: Open and map input files asynchronously on Windows.
Profiling revealed that the majority of lld's execution time on Windows was
spent opening and mapping input files. We can reduce this cost significantly
by performing these operations asynchronously.

This change introduces a queue for all operations on input file data. When
we discover that we need to load a file (for example, when we find a lazy
archive for an undefined symbol, or when we read a linker directive to
load a file from disk), the file operation is launched using a future and
the symbol resolution operation is enqueued.  This implies another change
to symbol resolution semantics, but it seems to be harmless ("ninja All"
in Chromium still succeeds).

To measure the perf impact of this change I linked Chromium's chrome_child.dll
with both thin and fat archives.

Thin archives:

Before (median of 5 runs): 19.50s
After: 10.93s

Fat archives:

Before: 12.00s
After: 9.90s

On Linux I found that doing this asynchronously had a negative effect on
performance, probably because the cost of mapping a file is small enough that
it becomes outweighed by the cost of managing the futures. So on non-Windows
platforms I use the deferred execution strategy.

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

llvm-svn: 289760
2016-12-15 04:02:23 +00:00
Peter Collingbourne c4e9482164 COFF: We no longer require lib.exe to test DLL exports.
llvm-svn: 289745
2016-12-15 00:11:17 +00:00
Davide Italiano 19d647b667 [LTO] Catch up with llvm. Modules without DL are now considered invalid.
llvm-svn: 289722
2016-12-14 21:58:26 +00:00
Peter Smith 532bc984f5 [ELF] Accept first SHT_ARM_ATTRIBUTES section
The eglibc library, as used by Ubuntu 14.04 requires the presence of an
SHT_ARM_ATTRIBUTES section in for the purposes of checking hard/soft float
compatibility when dlopen() is used. Unfortunately when the section is not
present dlopen() fails with a generic could not find file message.
    
This change makes lld keep the first .ARM.attributes section that it
encounters and propagates it to the output. This is not a complete
SHT_ARM_ATTRIBUTES implementation, that would involve reading the contents
of the section and joining each individual attribute. It should suffice
for a homogenous build all libraries and executables on the same system
with a compatible set of command line options.

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

llvm-svn: 289642
2016-12-14 10:36:12 +00:00
Peter Smith d92099991b [ELF] Add R_ARM_RELATIVE to relocations that can be applied to GotSection
When compiling -fpie and linking with the --pie option the R_ARM_GOTBREL
relocation to D is resolved by writing the value of D into the .got slot
and emitting an R_ARM_RELATIVE relocation for it.
    
This changes adds the R_ARM_RELATIVE relocation to the switch in
relocateOne() so we can process the GotSection relocation to write the
value of the variable as well as emitting the dynamic relocation.

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

llvm-svn: 289527
2016-12-13 10:42:05 +00:00
Rafael Espindola 5f51ed1ca7 Simplify the test. NFC.
llvm-svn: 289499
2016-12-12 23:52:21 +00:00
Simon Atanasyan 2903a8a11f [ELF][MIPS] Calculate default _gp value relative to the GPREL section with the lowest address
llvm-svn: 289471
2016-12-12 21:34:11 +00:00
Simon Atanasyan b9666655c2 [ELF][MIPS] Fix .MIPS.options ri_gp_value on MIPS64
The VA of _gp was being truncated to 32 bits when calling getVa(), but
for 64bit MIPS we need to write a 64 bit value to .MIPS.options.

Patch by Alexander Richardson.

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

llvm-svn: 289432
2016-12-12 14:30:18 +00:00
Peter Collingbourne 8b65e51b73 COFF: Load inputs immediately instead of adding them to a queue.
This patch replaces the symbol table's object and archive queues, as well as
the convergent loop in the linker driver, with a design more similar to the
ELF linker where symbol resolution directly causes input files to be added to
the link, including input files arising from linker directives. Effectively
this removes the last vestiges of the old parallel input file loader.

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

llvm-svn: 289409
2016-12-11 22:15:25 +00:00
Sanjoy Das fd4016b7c7 Fix TBAA metadata
The existing tbaa metadata in the test is ill-formed, and fails the
verifier after r289402.

llvm-svn: 289405
2016-12-11 21:10:11 +00:00
Rui Ueyama 327705d17d Create a TPI stream only when /debugpdb is given.
Adding type records to TPI stream is too time consuming.
It is reported that linking chrome_child.dll took 5 minutes.

llvm-svn: 289330
2016-12-10 17:23:23 +00:00
Rafael Espindola dd9dd488fc Fix a bogus warning.
We first decide that the symbol is global, than that it should have
version foo. Since it was already not the default version, we were
producing a bogus warning.

llvm-svn: 289284
2016-12-09 22:40:49 +00:00
Peter Collingbourne 79a5e6b1b7 COFF: New symbol table design.
This ports the ELF linker's symbol table design, introduced in r268178,
to the COFF linker.

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

llvm-svn: 289280
2016-12-09 21:55:24 +00:00
Meador Inge b06147db0c [ELF] Fix test case thinko from r289152
It was pointed out in a post-commit review that the tests
were structured oddly.  Fixed thusly.

llvm-svn: 289278
2016-12-09 21:51:37 +00:00
Rafael Espindola 157c51dce1 Add support for R_X86_64_GOT64.
llvm-svn: 289277
2016-12-09 21:46:39 +00:00
Hans Wennborg 1818e65aad COFF: Support both /lldmap and /lldmap:<file>
The former option bases the filename on the output name, e.g. if the
link output is a.exe, the map will be written to a.map. This matches the
behaviour of link.exe's /MAP option and is useful for creating a map
file of each executable when building a large project.

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

llvm-svn: 289271
2016-12-09 20:54:44 +00:00
Rui Ueyama df41b13b09 Remove `REQUIRES: shell` hack to workaround an echo issue.
These tests are disabled on Windows, but they seem to work just fine now,
so I'll enable them.

llvm-svn: 289251
2016-12-09 18:49:37 +00:00