Commit Graph

227 Commits

Author SHA1 Message Date
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
Rui Ueyama 48c3f1cebc Split LinkerScript<ELFT>::createSections.
Also avoid to use a lambda that is called only once.

llvm-svn: 278445
2016-08-12 00:27:23 +00:00
Rui Ueyama 1602421c85 Replace a variadic forwarding template function with less complex ones.
llvm-svn: 278439
2016-08-11 23:22:52 +00:00
Rui Ueyama 2c3f501052 Make class hierarchy more shallow.
LayoutInputSection is a dummy class and does not need any features
that the actual implementation (InputSection class) provides.

llvm-svn: 278430
2016-08-11 22:06:55 +00:00
Rui Ueyama f4a30a5d89 Remove trailing whitespace.
llvm-svn: 278420
2016-08-11 21:30:42 +00:00
Rui Ueyama dd81fe3156 Add comments.
llvm-svn: 278408
2016-08-11 21:00:02 +00:00
Eugene Leviant ceabe80e97 [ELF] Symbol assignment within output section description
llvm-svn: 278322
2016-08-11 07:56:43 +00:00
George Rimar e32a3598bc [ELF] - Linkerscript: implement SIZEOF_HEADERS.
SIZEOF_HEADERS - Return the size in bytes of the output file’s headers.

It is is a feature used in FreeBsd script, for example.
There is a discussion on PR28688 page about it.

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

llvm-svn: 278204
2016-08-10 07:59:34 +00:00
Rui Ueyama edc521f192 Remove unreachable `return`. NFC.
llvm-svn: 278096
2016-08-09 04:50:26 +00:00
Rui Ueyama 1034c9e342 Remove isOutputDynamic and use Out<ELFT>::DynSymTab instead.
This patch is to not instantiate DynSymTab and DynStrTab if the
output is not a dynamic output.

llvm-svn: 278095
2016-08-09 04:42:01 +00:00
Rui Ueyama a2acc93140 Simplify. NFC.
llvm-svn: 277794
2016-08-05 01:25:45 +00:00
Rui Ueyama 808d13ea49 Move invariants outside of a lambda. NFC.
llvm-svn: 277791
2016-08-05 01:05:01 +00:00
Rui Ueyama 36c1cd235a Make combine() non-member function.
Because this function depends only on its arguments.

llvm-svn: 277790
2016-08-05 01:04:59 +00:00
Rui Ueyama 742c38361b Split InputSectionDescription::Sort into SortInner and SortOuter.
Summary:
The comparator function to compare input sections as instructed by
SORT command was a bit too complicated because it needed to handle
four different cases. This patch split it into two function calls.

This patch also simplifies the parser.

Reviewers: grimar

Subscribers: llvm-commits

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

llvm-svn: 277780
2016-08-04 22:27:00 +00:00
Rafael Espindola a4b41dca31 Remove redundant argument.
But always set Script<ELFT>::X->OutputSections.

llvm-svn: 277720
2016-08-04 12:13:05 +00:00
George Rimar eefa758ee2 [ELF] - Linkerscript: implemented ASSERT() keyword.
ASSERT(exp, message)
Ensure that exp is non-zero. If it is zero, then exit the linker with an error
code, and print message.

ASSERT is useful and was seen in few projects in the wild.

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

llvm-svn: 277710
2016-08-04 09:29:31 +00:00
George Rimar 9e5386ceae [ELF] - Linkerscript: Fixed SORT_BY_ALIGNMENT sorting order.
According to spec:
"SORT_BY_ALIGNMENT will sort sections into descending order by 
alignment before placing them in the output file"

Previously they were sorted into ascending order.

llvm-svn: 277706
2016-08-04 08:56:17 +00:00
Eugene Leviant c7611fc567 [ELF] Linkerscript: remove repeated sections in filter()
llvm-svn: 277703
2016-08-04 08:20:23 +00:00
Rui Ueyama c163318b21 Remove buggy PROVIDE-in-output-description command.
With the previous change, it is now obvious that readProvide in
this context appended new commands to a wrong command list.
It was mistakenly adding new commands to the top level.
Thus, all commands inside output section descriptions were
interpreted as they were written on top level.

PROVIDE command naturally requires symbol assignment support
in the output section description. We don't have that one yet.
I removed the implementation because there's no way to fix it now.
We can resurrect the test once we support the symbol assignment
(with a modification to detect errors that we failed to find as
described.)

llvm-svn: 277687
2016-08-04 02:03:29 +00:00
Rui Ueyama 104165643e Make ScriptParser::read* functions more functional style.
Previously, many read* functions created new command objects and
add them directly to the top-level data structure. This is not
work for some commands because some commands, such as the assignment,
can appear inside and outside of the output section description.

This patch is to not append objects to the top-level data structure.
Callers are now responsible to do that.

llvm-svn: 277686
2016-08-04 02:03:27 +00:00
Rui Ueyama 965827d674 Make filler expression compatible with gold.
Previously, a decimal filler expression is interpreted as a byte value.
Gold on the other hand use it as a 32-bit big-endian value.
This patch fixes the compatibility issue.

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

llvm-svn: 277680
2016-08-03 23:25:15 +00:00
Rui Ueyama e7f912cd8f Create only one vector instead of two.
In this for-loop, we append elements from one vector to another,
which is a bit inefficient.

llvm-svn: 277653
2016-08-03 21:12:09 +00:00
Nico Weber 2e36772caf Revert 277594, it caused PR28827
llvm-svn: 277599
2016-08-03 14:37:57 +00:00
Rafael Espindola a348532ec3 Remove redundant argument.
llvm-svn: 277594
2016-08-03 13:21:16 +00:00