427 Commits

Author SHA1 Message Date
Eugene Leviant 2b9698d609 [ELF] Bypass section type check
Differential revision: https://reviews.llvm.org/D28761


git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293276 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 11:01:43 +00:00
Rui Ueyama d848fe3453 Rename NotFlags -> NegFlags.
Negative flags are still bit flags, so I think "not flag" is a very good name.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293143 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 02:58:59 +00:00
Rui Ueyama 97a15effb1 Use StringRef::lower only once instead of calling ::tolower many times.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293142 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 02:58:39 +00:00
Rui Ueyama a5848a95c9 Split ScriptParser::readMemory.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293141 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 02:58:19 +00:00
Meador Inge 96ebc3749e [LinkerScript] Implement MEMORY command
As specified here:

* https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY

There are two deviations from what is specified for GNU ld:

  1. Only integer constants and *not* constant expressions
     are allowed in `LENGTH` and `ORIGIN` initializations.

  2. The `I` and `L` attributes are *not* implemented.

With (1) there is currently no easy way to evaluate integer
only constant expressions.  This can be enhanced in the
future.

With (2) it isn't clear how these flags map to the `SHF_*`
flags or if they even make sense for an ELF linker.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292875 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 02:34:00 +00:00
George Rimar 1f8cbbf71b [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.
It is used in linux kernel script:
http://lxr.free-electrons.com/source/arch/x86/kernel/vmlinux.lds.S#L140

Though CONSTRUCTORS is ignored for ELF.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292777 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 09:36:19 +00:00
Rafael Espindola a0862ed9ec Reduce code duplication when allocating program headers.
This will simplify a bug fix.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292642 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 20:41:18 +00:00
George Rimar 6f3e95eb9c [ELF] - Do not crash when assign common symbol's values in script
Found that during attempts of linking linux kernel,
previously we partially duplicated code from getOutputSection(),
and it missed commons symbol case.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292594 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 09:45:36 +00:00
George Rimar 3bc831b6b7 [ELF] - Support optional comma after output section command.
I found this when tried to link linux kernel with LLD:

https://github.com/torvalds/linux/blob/master/arch/x86/entry/vdso/vdso-layout.lds.S#L86

Output section command can have optional comma at the end:

.text		: { *(.text*) }			:text	=0x90909090,

It was documented about 3 years ago for binutils:
https://sourceware.org/ml/binutils/2014-04/msg00045.html

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292225 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 15:32:12 +00:00
Rafael Espindola 6c95c4c55a 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291569 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 16:37:24 +00:00
Meador Inge afebff316f [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).

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291459 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 18:36:57 +00:00
Rui Ueyama 68320f36fa 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291413 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 01:42:02 +00:00
Rafael Espindola d357714dfc 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291107 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 14:20:35 +00:00
Rui Ueyama edec367af1 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290411 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23 03:19:09 +00:00
Eugene Leviant 0e4d14e16d [ELF] Linkerscript: print location of undefined symbol usage
Differential revision: https://reviews.llvm.org/D27194


git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290339 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-22 13:13:12 +00:00
George Rimar 08f0bd3705 [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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290247 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-21 09:42:25 +00:00
Rui Ueyama 3f9c889ebd 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290241 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-21 08:40:09 +00:00
George Rimar 1cbc6fdfe5 [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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290238 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-21 08:11:49 +00:00
Rafael Espindola 61db4e7227 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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290136 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 21:21:07 +00:00
Rafael Espindola 1b45bb0b27 Detemplate PhdrEntry. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290115 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 17:01:01 +00:00
Rui Ueyama 54b01a52e8 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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290062 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-18 14:06:06 +00:00
Rui Ueyama 6c1d620c67 [ELF] - Linkerscript: Implement two argument version of ALIGN()
Fixes http://llvm.org/PR31129

Patch by Alexander Richardson!

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@289968 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 18:19:35 +00:00
George Rimar 1654443561 [ELF] - Apply format. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@289823 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 15:38:09 +00:00
George Rimar c2bb683270 [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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@289782 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 07:27:28 +00:00
Rafael Espindola f4830b05fb Fix parsing when one extern follows another.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@289224 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-09 16:44:05 +00:00