Commit Graph

2991 Commits

Author SHA1 Message Date
Simon Atanasyan 2bd98af563 [ELF][MIPS] Exclude mips .got from PT_GNU_RELRO segment
On MIPS .got section cannot be included into the PT_GNU_RELRO segment.
Sometimes it might work, but in general it is unsupported. One of the
problem is that all sections marked by SHF_MIPS_GPREL should be grouped
together because data in these sections is addressable with a gp
relative address, but such sections might be writable.

This patch exclude mips .got from PT_GNU_RELRO segment and group
SHF_MIPS_GPREL sections.

llvm-svn: 292161
2017-01-16 21:17:23 +00:00
Simon Atanasyan 97a42ea896 [ELF][MIPS] Remove redundant checkings from test cases. NFC
llvm-svn: 292160
2017-01-16 21:17:09 +00:00
Rafael Espindola 41a93a3edf Give priority to linker scripts over preemption.
LLD exports symbols that are also present in used shared libraries to
make sure they are preempted at runtime. That is a reasonable default,
but we must allow for it to be overwritten with linker script. If we
don't, libraries that expect to be able to hide a c++ delete operator
will fail.

This should fix the firebird build.

llvm-svn: 292146
2017-01-16 17:35:23 +00:00
Rui Ueyama 1705f99c77 Add -print-map and -M options.
llvm-svn: 292046
2017-01-15 02:52:34 +00:00
Peter Collingbourne 6f24fdb6a0 COFF: Change the /lldmap output format to be more like the ELF linker.
Differential Revision: https://reviews.llvm.org/D28717

llvm-svn: 291990
2017-01-14 03:14:46 +00:00
Rafael Espindola 7c783a49a2 Try to fix the windows bots.
llvm-svn: 291989
2017-01-14 02:45:53 +00:00
Rafael Espindola 1ebfc59c89 Implement -Map.
The format is not exactly the same as the one in bfd since bfd always
follows a linker script and prints it along.

llvm-svn: 291958
2017-01-13 21:05:46 +00:00
Rafael Espindola 8a59f5c79f Don't add DT_INIT/DT_FINI for undef and shared symbols.
The freebsd dynamic linker doesn't check if the value is null (and it
is reasonable for it to do that). That means that producing a .so with
a null DT_INIT/DT_FINI causes the base address to be called.

This should fix the libreoffice build.

llvm-svn: 291944
2017-01-13 19:18:11 +00:00
George Rimar 1e799942b3 [ELF] - Move the addition of synthetics from addPredefinedSections()
These were 3 last synthetics that were added in addPredefinedSections() instead
of createSyntheticSections(). Now it is possible to move addition to correct common place.

Also patch fixes testcase which discards .shstrtab, by restricting doing that.

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

llvm-svn: 291908
2017-01-13 16:18:15 +00:00
Rafael Espindola bec58f9034 Allow mixing nobits and progbits.
The effect is that the nobits section gets space allocated on disk.

Both bfd and gold allow this with linker scripts. To try to keep
things simple in lld, always allow it for now.

llvm-svn: 291795
2017-01-12 19:16:15 +00:00
George Rimar f09519c362 [ELF] - Do not crash if user section has name equal to one of synthetic sections.
Previously we just crashed when had user defined
section .shstrtab, for example. Which name equals to synthetic one,
but have different type.

Testcase reveals an issue.

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

llvm-svn: 291765
2017-01-12 13:00:31 +00:00
George Rimar 1743e55e34 [ELF] - Make x86 unknown relocations messages to be consistent with x64 ones
Addded quotes to be consistent with x64 messages,
where quotes were used for nicer reporting 'Unknown' relocations initially.

llvm-svn: 291752
2017-01-12 09:09:15 +00:00
George Rimar 66666360de [ELF] - Explicitly list supported relocations for x64 target.
The same we did for x86 earlier:
list supported relocations explicitly and error out on unknown.

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

llvm-svn: 291751
2017-01-12 09:00:17 +00:00
Rui Ueyama 5289662e4a PDB: Merge type info.
This patch is to merge type info in multiple .debug$T sections.

One mystery that needs to be solved is that it is not clear how
the MSVC linker uses TPI and IPI streams. Both streams contain
type info, and it is not obvious what kind of record should go
which.

dumppdb command in microsoft-pdb repository prints out IPI stream
contents as "IDs" and TPI stream as "TYPES", but looks like the tool
don't really care about which stream type recrods were read from.

For now, in this patch, I emit all type records to TPI stream.
It might just work with other tools. If not, we need to investigate
it more.

llvm-svn: 291739
2017-01-12 03:09:25 +00:00
Rafael Espindola 79114a673e Make the -b binary .data section rw.
This matches what bfd and gold do. It also matches the common flags of
other .data sections.

llvm-svn: 291674
2017-01-11 15:13:05 +00:00
George Rimar 7fa220f5f1 [ELF] - Ignore R_386_NONE.
We had an error when met this relocation
after latest changes aboult listing
x86 relocations explicitly.

Since we support R_X86_64_NONE,
and GNU ld supports R_386_NONE,
it seems reasonable to have.

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

llvm-svn: 291672
2017-01-11 14:20:13 +00:00
George Rimar 57b0e6a5c9 [ELF] - Explicitly list supported relocations for x86 target.
Previously some value was returned by default for relocations by getRelExpr(),
even if relocation actually was not supported.

This is orthogonal alternative to D28094.
Instead of implementing probably useless R_386_PC8/R_386_8 relocations,
this patch uses them in a testcase to demonstrate what happens
when LLD mets unsupported relocations.

Patch passes all testcases and changes logic only for x86.

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

llvm-svn: 291658
2017-01-11 08:29:52 +00:00
Rafael Espindola b7e2ee2aba Give local binding to VER_NDX_LOCAL symbols.
We were already dropping them from the dynamic symbol table, but the
regular symbol table was still listing them as globals.

llvm-svn: 291573
2017-01-10 17:08:13 +00:00
Rafael Espindola e999ddb8de Add support for anonymous local symbols.
This actually simplifies the code a bit as now all local symbols are
handled uniformly.

This should fix the build of www/webkit2-gtk3.

llvm-svn: 291569
2017-01-10 16:37:24 +00:00
Rui Ueyama 0697ae2ad9 Revert r291526: Re-enable /linkrepro test on Windows.
This broke the following two bots:

lld-x86_64-win7: the test failed because a diff command is not available
on that bot. That's a configuration error of the bot and will be fixed soon.

llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast: "tar xf" failed on that
bot. I suspect that it is due to the maximum path limitation on Windows.
A build directory contains a buildbot name, so it's longer than usual on
that machine. On Windows, many filesystem operations fail if a path is
longer than 255 characters. I'll try to address that in another patch.

llvm-svn: 291527
2017-01-10 02:08:37 +00:00
Rui Ueyama e98516ff99 Re-enable /linkrepro test on Windows.
I think generated tar files are more compatible with old tar commands
because of r291494 and r291340, so I want to enable this test on buildbots.

llvm-svn: 291526
2017-01-10 01:37:37 +00:00
Peter Collingbourne feb6629d6d ELF: Reserve space for copy relocations of read-only symbols in relro.
When reserving copy relocation space for a shared symbol, scan the DSO's
program headers to see if the symbol is in a read-only segment. If so,
reserve space for that symbol in a new synthetic section named .bss.rel.ro
which will be covered by the relro program header.

This fixes the security issue disclosed on the binutils mailing list at:
https://sourceware.org/ml/libc-alpha/2016-12/msg00914.html

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

llvm-svn: 291524
2017-01-10 01:21:50 +00:00
Peter Collingbourne 628ec9f193 ELF: Place relro sections after non-relro sections in r/w segment.
This is in preparation for my next change, which will introduce a relro
nobits section. That requires that relro sections appear at the end of the
progbits part of the r/w segment so that the relro nobits section can appear
contiguously.

Because of the amount of churn required in the test suite, I'm making this
change separately.

llvm-svn: 291523
2017-01-10 01:21:30 +00:00
Meador Inge 9a77ea8a86 [ELF] Fix `_gp` linker script test
Rafael suggested in review to wrap the `.` in an
`ABSOLUTE` op to force the section to be in the
*ABS* "section":

  * http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170109/417865.html

llvm-svn: 291501
2017-01-09 23:16:01 +00:00
Rui Ueyama 817c9d66f0 Support non-regular output files.
This patch enables something like "-o /dev/null".
Previouly, it failed because such files cannot be renamed.

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

llvm-svn: 291496
2017-01-09 23:07:05 +00:00
Peter Collingbourne c39e5d64b3 ELF: Discard .gnu.linkonce.* sections.
The linkonce feature is a sort of proto-comdat. As far as I am aware no
compiler produces linkonce sections anymore, but some glibc i386 object
files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
sections. Drop those sections to avoid duplicate symbol errors.

This is glibc PR20543, we should remove this hack once that has been
fixed for a while.

Fixes PR31215.

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

llvm-svn: 291474
2017-01-09 20:26:33 +00:00
Meador Inge 8f1f3c40f6 [ELF] Allow defined symbols to be assigned from linker script
This patch allows for linker scripts to assign a new value
to a symbol that is already defined (either in an object file
or the linker script itself).

llvm-svn: 291459
2017-01-09 18:36:57 +00:00
Rui Ueyama ec1c75e059 Add linker-script-included files to reproduce tar files.
Previously, files added using INCLUDE directive weren't added
to reproduce archives. In this patch, I defined a function to
open a file and use that from Driver and LinkerScript.

llvm-svn: 291413
2017-01-09 01:42:02 +00:00
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