Commit Graph

250 Commits

Author SHA1 Message Date
Rui Ueyama 86c5fb8296 Fix bug in -nostdlib.
We still have to skip a token inside SEARCH_DIR() when -nostdlib is
specified. Previuosly, we didn't skip it, so it caused a parse error.

llvm-svn: 281001
2016-09-08 23:26:54 +00:00
Rafael Espindola c0028d3d3b Reduce templating. NFC.
llvm-svn: 280986
2016-09-08 20:47:52 +00:00
Rafael Espindola 042a3f209b Compute section names only once.
This simplifies error handling as there is now only one place in the
code that needs to consider the possibility that the name is
corrupted. Before we would do it in every access.

llvm-svn: 280937
2016-09-08 14:06:08 +00:00
Eugene Leviant 36fac7f0d0 Linker script: implement ALIGNOF
Differential revision: https://reviews.llvm.org/D24141

llvm-svn: 280915
2016-09-08 09:08:30 +00:00
George Rimar 6c55f0e35e [ELF] - Apply clang-format to LinkerScript.cpp, NFC.
llvm-svn: 280911
2016-09-08 08:20:30 +00:00
George Rimar 884e786d38 [ELF] - Linkerscript: simplify access to templated methods from parser.
Previous way of accessing templated methods was a bit bulky,
Patch introduces small interface based solution.

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

llvm-svn: 280910
2016-09-08 08:19:13 +00:00
George Rimar a14b13d867 [ELF] - Linkerscript: create multiple output sections for inputs with different attributes.
Previously we combined sections by name if linkerscript was used.
For that we had to disable SHF_MERGE handling temporarily, but then
found that implementing it properly will require additional complexity layers like
subsections or something.
At the same time looks we can live with multiple output sections approach for now.
That patch do this change.

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

llvm-svn: 280801
2016-09-07 10:46:07 +00:00
Eugene Leviant db741e7203 Support ABSOLUE keyword in symbol assignments
This patch allows making section defined symbols absolute:
.foo : {
  begin_foo = ABSOLUTE(.);
  *(.foo)
}

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

llvm-svn: 280788
2016-09-07 07:08:43 +00:00
Rui Ueyama adcdb664cb Simplify a boolean expression by using the De Morgan's law.
llvm-svn: 280766
2016-09-06 22:50:48 +00:00
Rui Ueyama 25150e8b0d Add a comment.
llvm-svn: 280724
2016-09-06 17:46:43 +00:00
George Rimar ff1f29e0f6 [ELF] - Linkerscript: implemented FILL command as alias for =fillexpr
Patch implements FILL just as alias for =fillexpr. 
This allows to make implementation much shorted and simpler than D24186.

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

llvm-svn: 280708
2016-09-06 13:51:57 +00:00
Simon Atanasyan eaeafb2b4f [ELF] PR30221 - linker script expression parser does not accept '~'
The patch adds support for both '-' and '~' unary expressions. Also it
brings support for signed numbers is expressions.

https://llvm.org/bugs/show_bug.cgi?id=30221

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

llvm-svn: 280546
2016-09-02 21:54:35 +00:00
George Rimar c91930a17f [ELF] - Use std::regex instead of hand written logic in elf::globMatch()
Use std::regex instead of hand written matcher.

Patch based on code and ideas of Rui Ueyama.

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

llvm-svn: 280544
2016-09-02 21:17:20 +00:00
Rui Ueyama 6c7ad13f89 Add -nostdlib.
llvm-svn: 280528
2016-09-02 19:20:33 +00:00
Rui Ueyama a27eeccade Dispatch without hash table lookup.
Cmd used to be the single central place to dispatch. It is not longer
the case because we have a logic for readProvideOrAssignment().
This patch removes the hash table so that evrything is in a single
function. This is slightly verbose but should improve readability.

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

llvm-svn: 280524
2016-09-02 18:52:41 +00:00
Rui Ueyama 626e0b08ac Add comments.
llvm-svn: 280515
2016-09-02 18:19:00 +00:00
George Rimar 9f2f7ad98b [ELF] - Linkerscript: add support for suffixes in numbers.
Both bfd and gold accept:
foo = 1K;
bar = 1M;
zed = 1H;

And lowercase forms: k, m, h.
Patch adds support for that.

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

llvm-svn: 280494
2016-09-02 16:01:42 +00:00
Eugene Leviant 97403d15ee Eliminate LayoutInputSection class
Previously we used LayoutInputSection class to correctly assign
symbols defined in linker script. This patch removes it and uses
pointer to preceding input section in SymbolAssignment class instead.

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

llvm-svn: 280348
2016-09-01 09:55:57 +00:00
Rui Ueyama 95769b4a29 Linker script: support VERSION command.
Summary:
VERSION commands define symbol versions. The grammar of the
commnad is as follows

  VERSION { version-script-commands }

where version-script-commands is

  [ name ] { version-definitions }.

Note that we already support version-script-commands because
it is being used for version script command.

This patch is based on George's patch https://reviews.llvm.org/D23609

Reviewers: grimar

Subscribers: llvm-commits

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

llvm-svn: 280284
2016-08-31 20:03:54 +00:00
Petr Hosek e5d3ca5031 [ELF] Linkerscript: define symbols outside SECTIONS
Symbol assignments outside of SECTIONS command need to be created
even when SECTIONS command is not used.

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

llvm-svn: 280252
2016-08-31 15:31:17 +00:00
George Rimar 20b6598c10 [ELF] - Remove VersionScriptParser class and move the members to ScriptParser
Patch removes VersionScriptParser class and moves the members to ScriptParser
It opens road for implementation of VERSION linkerscript command.

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

llvm-svn: 280212
2016-08-31 09:08:26 +00:00
Eugene Leviant 20889c51b7 Allow adding start/end symbols to any section
Allows adding start and/or end symbols to special output sections,
like .eh_frame_hdr, which aren't lists of regular input sections. 

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

llvm-svn: 280205
2016-08-31 08:13:33 +00:00
George Rimar 96659df09c [ELF] - Linkerscript: implemented ADDR command.
ADDR(section)
Return the absolute address (the VMA) of the named section.

Used in the wild, eg.: https://searchcode.com/file/53617342/arch/x86/kernel/vmlinux.lds.S

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

llvm-svn: 280070
2016-08-30 09:54:01 +00:00
George Rimar a2496cbed4 [ELF] - Fix for: bug 29115 - linkerscript does not support non-wildcard filename spec.
FreeBSD/mips script has non-wildcard filename specifications:
.text :
{
 start.o(.text*)

Patch adds support for that, this is PR29115.

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

llvm-svn: 280069
2016-08-30 09:46:59 +00:00
Rui Ueyama 2c8f1f048c Make lld actually compatible with gold in terms of filler handling.
GNU gold handles output section fillers as 32-bit values.
This patch makes LLD compatible with that behavior.

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

llvm-svn: 280018
2016-08-29 22:01:21 +00:00
Rafael Espindola cc3dd629ee Add support for '|' in expressions.
llvm-svn: 279480
2016-08-22 21:33:35 +00:00
Rui Ueyama 464daadc3d Do not add .interp, .dynamic nor .eh_frame_hdr to segments just by type.
Summary:
We previously added these output sections to segments just by type.
Therefore, if there's a PHDRS command like this

  PHDRS {
    headers PT_PHDR PHDRS;
    interp PT_INTERP;
  }

  SECTIONS {
    . = SIZEOF_HEADERS;
    .interp : { *(.interp) } :text
  }

then .interp was added to "interp" segment even though the linker
is not instructed to do so by SECTIONS command. This patch removes
the default behavior to simplify.

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

llvm-svn: 279414
2016-08-22 04:55:20 +00:00
George Rimar e1937bb524 [ELF] - Give automatically generated __start_* and __stop_* symbols default visibility.
This patch is opposite to D19024, which made this symbols to be hidden by default.

Unfortunately FreeBSD loader wants to see
start_set_modmetadata_set/stop_set_modmetadata_set in the dynamic symbol table. 
They were not placed there because had hidden visibility.

Patch makes them to have default visibility again.

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

llvm-svn: 279262
2016-08-19 15:36:32 +00:00
George Rimar db24d9c3e8 [ELF] - Linkerscript: implemented SUBALIGN() command.
You can force input section alignment within an output section by using SUBALIGN. The
value specified overrides any alignment given by input sections, whether larger or smaller.

SUBALIGN is used in many projects in the wild.

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

llvm-svn: 279256
2016-08-19 15:18:23 +00:00
Eugene Leviant 3f675e38bd [ELF] Don't add input sections twice when linker script is used
llvm-svn: 279036
2016-08-18 07:27:37 +00:00
Petr Hosek 0df80bef96 [ELF] Linkerscript: support assignment outside SECTIONS
We only support assignments inside SECTIONS, but this does not match
the behavior of GNU linker which also allows them outside SECTIONS.
The only restriction on assignments outside SECTIONS is that they
cannot reference . (they have to be absolute expressions).

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

llvm-svn: 279033
2016-08-18 04:34:27 +00:00
Rui Ueyama 6ad7dfcc1e Merge readAt and readAlign.
Now that they are identical.

llvm-svn: 278953
2016-08-17 18:59:16 +00:00
George Rimar 545afafb70 [ELF] - Linkerscript: make readAt() signature to be consistent with others read*(). NFC.
llvm-svn: 278931
2016-08-17 14:48:17 +00:00
George Rimar 206fffa192 Attemp to fix linux build bot after r278911 ("[ELF] - linkerscript AT keyword (in output section description) implemented.")
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/26289/steps/build_Lld/logs/stdio

llvm-svn: 278914
2016-08-17 08:16:57 +00:00
George Rimar 8ceadb38a8 [ELF] - linkerscript AT keyword (in output section description) implemented.
The linker will normally set the LMA equal to the VMA. 
You can change that by using the AT keyword.
The expression lma that follows the AT keyword specifies 
the load address of the section.

Patch implements this keyword.

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

llvm-svn: 278911
2016-08-17 07:44:19 +00:00
Michael J. Spencer e2cc07bc0b [ELF] Set MAXPAGESIZE to 2MiB on x86-64 to match bfd and gold.
The FreeBSD kernel relies on this behavior to not overwrite the boot loader.

llvm-svn: 278889
2016-08-17 02:10:51 +00:00
Eugene Leviant f9bc3bd2cf [ELF] Ignore .interp section in case linker script specifies PHDRS without PT_INTERP
llvm-svn: 278781
2016-08-16 06:40:58 +00:00
Petr Hosek a35e39ca2e [ELF] Linkerscript: support hidden symbols assignments
This add support for HIDDEN command which can be used to define
a symbol that will be hidden and won't be exported.

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

llvm-svn: 278770
2016-08-16 01:11:16 +00:00
Eugene Leviant b6f1bb13ae [ELF] Linkerscript: fix bug in assignOffsets (check Sym for non-null)
llvm-svn: 278663
2016-08-15 09:19:51 +00:00
George Rimar 8f66df92ba [ELF] - Linkerscript: fix VA value assigned to sections when using constraints.
Previously we searched output section by name to assign VA. That did not
work in the case when multiple output sections with different constraints were defined in script.
Testcase shows the possible issue scenario, patch fixes the issue.

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

llvm-svn: 278561
2016-08-12 20:38:20 +00:00
George Rimar b6c52e8dfa [ELF] - Remove excessive loop in LinkerScript<ELFT>::assignAddresses()
After 278461 "Create only one section for a name in LinkerScript."
this loop is excessive. 
Patch also reorders code slightly to use early return.

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

llvm-svn: 278554
2016-08-12 19:32:45 +00:00
George Rimar 06ae683620 [ELF] - Linkerscript: reimplemented output sections constrains matching functionality.
Previously filtering that was used worked incorrectly. 
For example for next script it would just remove both sections completely:

SECTIONS { 
. = 0x1000;
.aaa : ONLY_IF_RW { *(.aaa.*) } 
. = 0x2000;
.aaa : ONLY_IF_RO { *(.aaa.*) } 
}

Patch fixes above issues and adds testcase showing the issue. Testcase is a subset of
FreeBSD script which has:

.eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
...
.eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }

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

llvm-svn: 278486
2016-08-12 09:07:57 +00:00
Rui Ueyama 4f7500bfc2 Rename getSizeOfHeaders -> getHeaderSize.
We have getSectionSize for SIZEOF command. So, I think
getHeaderSize is a better name for SIZEOF_HEADERS.

llvm-svn: 278470
2016-08-12 04:00:22 +00:00
Rui Ueyama 2ab5f73d5a Early continue. NFC.
llvm-svn: 278465
2016-08-12 03:33:04 +00:00
Rui Ueyama 0c70d3ccb7 Simplify LinkerScript<ELFT>::createSections.
Previously, we were setting LayoutInputSection's OutputSection member
in createSections. Because when we create LayoutInputSectinos, we
don't know the output section for them, so we backfilled the member
in the function. This patch moves the code to backfill it to assignOffsets.

llvm-svn: 278464
2016-08-12 03:31:09 +00:00
Rui Ueyama 7ad9d6d2f0 Remove excessive parentheses.
llvm-svn: 278462
2016-08-12 03:25:25 +00:00
Rui Ueyama 0b9ce6a48a Create only one section for a name in LinkerScript.
Previously, we created two or more output sections if there are
input sections with the same name but with different attributes.
That is a wrong behavior. This patch fixes the issue.

One thing we need to do is to merge output section attributes.
Currently, we create an output section based on the first input
section's attributes. This may make a wrong output section
attributes. What we need to do is to bitwise-OR attributes.
We'll do it in a follow-up patch.

llvm-svn: 278461
2016-08-12 03:16:56 +00:00
Rui Ueyama f34d0e0875 Allocate LayoutInputSections using SpecificBumpPtrAllocator.
llvm-svn: 278453
2016-08-12 01:24:53 +00:00
Rui Ueyama 2de509c370 Remove OutputSectionBuilder::finalize.
The reason why we had to assign offsets only to sections that
don't contain layout sections were unclear. It turned out that
we can live without it.

llvm-svn: 278449
2016-08-12 00:55:08 +00:00
Rui Ueyama e5cc668eb8 Remove useless local variable.
llvm-svn: 278446
2016-08-12 00:36:56 +00:00