Commit Graph

7557 Commits

Author SHA1 Message Date
George Rimar 31a46b4835 [ELF] - Fix mistype in comment. NFC.
llvm-svn: 290510
2016-12-25 06:49:17 +00:00
George Rimar 58f84a01a3 [ELF] - Return file offset as address only for allocatable sections when building .gdb_index
This fixes issue revealed by r289961.

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

llvm-svn: 290419
2016-12-23 07:51:59 +00:00
Rui Ueyama 58841b45d0 Remove Driver::OwningMB and instead use make().
We managed new MemoryBuffers in different ways in LinkerScript.cpp and
Driver.cpp. With this patch, they are managed in the same way.

llvm-svn: 290411
2016-12-23 03:19:09 +00:00
Petr Hosek f367a2a52b [CMake] Add install target for the lld tool
This is necessary for the distribution targets which assume that
each component has an install target. This also moves the CMake
macros into a separate file akin to other LLVM projects.

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

llvm-svn: 290391
2016-12-23 00:22:47 +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 4c134ea3b8 Do not return null or Undefined from find{All,}ByVersion.
Vectors returned form that function contained nullptrs or Undefined symbols.
This patch filter them out. This makes use of the function a bit easier.

llvm-svn: 290334
2016-12-22 09:54:32 +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
Rui Ueyama 96aff3751f Define a getter function for a lazily-created object.
Previously, you had to call initDemangledSyms() before accessing DemangledSyms.
Now getDemangledSyms() initializes it and then returns it. So it is now less easy
to use it in a wrong way.

llvm-svn: 290323
2016-12-22 05:31:52 +00:00
Rui Ueyama b458841745 Simplify. NFC.
llvm-svn: 290321
2016-12-22 05:22:29 +00:00
Rui Ueyama e50e8071c2 Define a function to avoid a magic variable 0x3.
llvm-svn: 290320
2016-12-22 05:11:12 +00:00
Rui Ueyama 7323b4b788 Remove a typedef that is used only once.
llvm-svn: 290318
2016-12-22 04:40:56 +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
Rui Ueyama 4f2f50dc64 De-template DefinedSynthetic.
DefinedSynthetic is not created for a real ELF object, so it doesn't
have to be a template function. It has a virtual st_value, which is
either 32 bit or 64 bit, but we can simply use 64 bit.

llvm-svn: 290241
2016-12-21 08:40:09 +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
George Rimar 4fb6e79c65 [ELF] - Fix use of freed memory.
It was revealed by D27831.

If we have linkerscript that includes another one that sets OUTPUT for example:

RUN: echo "INCLUDE \"foo.script\"" > %t.script
RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script
then we do:

void ScriptParser::readInclude() {
...
  std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
  tokenize(MB->getMemBufferRef());
  OwningMBs.push_back(std::move(MB));
}

void ScriptParser::readOutput() {
...
    Config->OutputFile = unquote(Tok);
...
}
Problem is that OwningMBs are destroyed after script parser do its job.
So all Toks are dead and Config->OutputFile points to destroyed data.

Patch suggests to save all included scripts into using string Saver.

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

llvm-svn: 290238
2016-12-21 08:11:49 +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
Vitaly Buka 0b7de06a23 Fix build broken by changes in StringMatcher interface r290213
llvm-svn: 290231
2016-12-21 02:27:14 +00:00
Rui Ueyama 6e3595d6c5 Move a function defintion to make it static.
llvm-svn: 290215
2016-12-21 00:05:39 +00:00
Rui Ueyama e52614b5c7 Use ArrayRef instead of `const std::vector`.
llvm-svn: 290213
2016-12-20 23:17:00 +00:00
Rui Ueyama f7a7ab59af Move GlobPattern class from LLD to llvm/Support.
GlobPattern is a class to handle glob pattern matching. Currently
only LLD is using that, but technically that feature is not specific
to linkers, so in this patch I move that file to LLVM.

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

llvm-svn: 290212
2016-12-20 23:09:09 +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 c207a89c91 Remove `Compressed` member from InputSectionData.
This value is used only once, and we can compute a value.
So we don't need to save it.

llvm-svn: 290164
2016-12-20 05:47:55 +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
Rui Ueyama 312703116f Simplify type of Config->SymbolOrderingFile.
That variable was of type DenseMap<StringRef, unsigned>, but the
unsigned numbers needed to be monotonicly increasing numbers because
the implementation that used the variable depended on that fact.
That was an implementation detail and shouldn't have leaked into Config.

This patch simplifies its type to std::vector<StringRef>.

llvm-svn: 290151
2016-12-20 01:51:08 +00:00
Rui Ueyama a8529e2cb7 Inline a small function.
llvm-svn: 290150
2016-12-20 01:34:31 +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
Rafael Espindola 17cb7c0a2a Detemplate PhdrEntry. NFC.
llvm-svn: 290115
2016-12-19 17:01:01 +00:00
Rafael Espindola 29982b0f6b Use existing variable. NFC.
llvm-svn: 290112
2016-12-19 16:50:20 +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 8f687f71fb Remove inappropriate use of CachedHashStringRef.
Use of CachedHashStringRef makes sense only when we reuse hash values.
Sprinkling it to all DenseMap has no benefits and just complicates data types.
Basically we shouldn't use CachedHashStringRef unless there is a strong
reason to to do so.

llvm-svn: 290076
2016-12-19 03:14:16 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
George Rimar 607fa711b2 [ELF] - Use DWARFDebugPubTable parser class intead of hand-written parsing.
DWARFDebugPubTable was introduced recently and allows us to get rid of
code duplication in LLD.

llvm-svn: 290042
2016-12-17 10:18:05 +00:00
Zachary Turner b5381eef6f Fix compiler warning.
Differential Revision: https://reviews.llvm.org/D27860

llvm-svn: 290002
2016-12-16 23:12:58 +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
Peter Collingbourne c1ded7dcef COFF: Cache the result of library searches.
File system operations were still dominating the profile on Windows. In this
case we were spending a significant amount of our time repeatedly searching
for libraries as a result of processing linker directives. Address this
by caching whether we have already found a library with a given name. For
chrome_child.dll:

Before: 10.53s
After: 6.88s

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

llvm-svn: 289915
2016-12-16 03:45:59 +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 879a657680 [ELF] - Apply format (2). NFC.
llvm-svn: 289824
2016-12-15 15:38:58 +00:00
George Rimar 93c64025fc [ELF] - Apply format. NFC.
llvm-svn: 289823
2016-12-15 15:38:09 +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 232d11cb54 [ELF] - Attempt to fix ubuntu 64x buildbot (2).
Fixed inaccurate member type: uint32_t -> size_t
(http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/2984/steps/build/logs/stdio).

llvm-svn: 289796
2016-12-15 09:59:18 +00:00
George Rimar aff2530cf8 [ELF] - Attempt to fix ubuntu bot.
(http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/2982)

llvm-svn: 289792
2016-12-15 09:30:07 +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