Commit Graph

358 Commits

Author SHA1 Message Date
George Rimar da841c161d [ELF] - Removed unused code. NFC.
This branch was unused I believe,
as Tok can never be empty.

llvm-svn: 286802
2016-11-14 10:03:54 +00:00
George Rimar bb6c01e7c3 [ELF] - Add support for locals list in version script.
Previously we did not support anything except "local: *", patch changes that.

Actually GNU rules of proccessing wildcards are more complex than that (http://www.airs.com/blog/archives/300):
There are 2 iteration for wildcards, at first iteration "*" wildcards are ignored and handled at second iteration.

Since we previously decided not to implement such complex rules,
I suggest solution that is implemented in this patch. So for "local: *" case nothing changes,
but if we have wildcarded locals,
they are processed before wildcarded globals. 

This should fix several FreeBSD ports, one of them is jpeg-turbo-1.5.1 and
currently blocks about 5k of ports.

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

llvm-svn: 286713
2016-11-12 07:04:15 +00:00
Rui Ueyama 1bdaf3e30c Remove an overloaded function to simplify.
This version of addRegular is almost identical to the other except
it lacked "size" parameter.

llvm-svn: 286416
2016-11-09 23:37:40 +00:00
Rafael Espindola e08e78df6d Make OutputSectionBase a class instead of class template.
The disadvantage is that we use uint64_t instad of uint32_t for some
value in 32 bit files. The advantage is a substantially simpler code,
faster builds and less code duplication.

llvm-svn: 286414
2016-11-09 23:23:45 +00:00
Rafael Espindola 04a2e348bb Split Header into individual fields.
This is similar to what was done for InputSection.

With this the various fields are stored in host order and only
converted to target order when writing.

llvm-svn: 286327
2016-11-09 01:42:41 +00:00
Rafael Espindola 8f9026baff Don't add null and discarded sections to the global list.
Avoids having to skip them multiple times.

llvm-svn: 286261
2016-11-08 18:23:02 +00:00
Rui Ueyama e8a6102fa9 Rewrite CommonInputSection as a synthetic input section.
A CommonInputSection is a section containing all common symbols.
That was an input section but was abstracted in a different way
than the synthetic input sections because it was written before
the synthetic input section was invented.

This patch rewrites CommonInputSection as a synthetic input section
so that it behaves better with other sections.

llvm-svn: 286053
2016-11-05 23:05:47 +00:00
Rui Ueyama 8c6a5aaf15 Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.

  for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
    for (InputSectionBase<ELFT> *S : F->getSections())

It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.

This patch defines a vector that contains all input sections including
synthetic ones.

llvm-svn: 286051
2016-11-05 22:37:59 +00:00
Eugene Zelenko 22886a2853 Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes.
Differential revision: https://reviews.llvm.org/D26320

llvm-svn: 286030
2016-11-05 01:00:56 +00:00
Rui Ueyama f91282e1cf Add [<chars>] to the glob matcher to eliminate use of llvm::Regex.
Previously, it didn't support the character class, so we couldn't
eliminate the use fo llvm::Regex. Now that it is supported, we
can remove compileGlobPattern, which converts a glob pattern to
a regex.

This patch contains optimization for exact/prefix/suffix matches.

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

llvm-svn: 285949
2016-11-03 17:57:38 +00:00
Eugene Leviant db68845485 Use globMatch() instead of llvm::regex in linker scripts
This can speed up lld up to 5 times when linking applications 
with large number of sections and using linker script.

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

llvm-svn: 285895
2016-11-03 10:54:58 +00:00
Rui Ueyama 95642b95bd Remove Out::Pool and use make() instead.
llvm-svn: 285763
2016-11-01 23:09:07 +00:00
Rafael Espindola c96da1100d Remove second argument to readProvideOrAssignment.
With this expressions alone track if they are absolute or not.

llvm-svn: 285687
2016-11-01 11:30:45 +00:00
Rafael Espindola b0de56b59d The expr '.' is not absolute.
With this patch we keep track of the fact that . is a position in the
file and therefore not absolute. This allow us to compute relative
relocations that involve symbol that are defined in linker scripts
with '.'.

This fixes https://llvm.org/bugs/show_bug.cgi?id=30406

There is still more work to track absoluteness over the various
expressions, but this should unblock linking the EFI bootloader.

llvm-svn: 285641
2016-10-31 21:36:23 +00:00
Rafael Espindola 2f831dcafd Delay computation of IsAbsolute.
We parse linker scripts very early, but whether an expression is
absolute or not can depend on a symbol defined in a .o. Given that, we
have to delay the computation of IsAbsolute. We can do that by storing
an AST when parsing or by also making IsAbsolute a function like we do
for the expression value. This patch implements the second option.

llvm-svn: 285628
2016-10-31 19:56:37 +00:00
Rafael Espindola 63b4a37ef5 Simple numeric constants are absolute.
llvm-svn: 285621
2016-10-31 18:56:02 +00:00
Rafael Espindola a0aaa8a0a3 Mark a few more expressions as absolute.
llvm-svn: 285611
2016-10-31 18:20:34 +00:00
Rafael Espindola f661393ad6 Move IsAbsolute from SymbolAssignment to Expr.
And as a token of the new feature, make ALIGNOF always absolute.

This is a step in making it possible to have non absolute symbols out
of output sections.

llvm-svn: 285608
2016-10-31 17:43:38 +00:00
Rafael Espindola 498ed714f8 Simplify. NFC.
No need to subtract then add Sec->getVA().

llvm-svn: 285580
2016-10-31 14:44:41 +00:00
Rafael Espindola 3dabfc6b0d Correctly merge visibility of linkerscript created symbols.
llvm-svn: 285567
2016-10-31 13:14:53 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rafael Espindola 093abab817 Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is
simple.

llvm-svn: 285322
2016-10-27 17:45:40 +00:00
Rafael Espindola 1854a8ebb8 Delete trivial getters. NFC.
llvm-svn: 285190
2016-10-26 12:36:56 +00:00
Rafael Espindola 0e090522c8 Read section headers upfront.
Instead of storing a pointer, store the members we need.

The reason for doing this is that it makes it far easier to create
synthetic sections. It also avoids reading data from files multiple
times., which might help with cross endian linking and host
architectures with slow unaligned access.

There are obvious compacting opportunities, but this already has mixed
results even on native x86_64 linking.

There is also the possibility of better refactoring the code for
handling common symbols, but this already shows that a custom class is
not necessary.

llvm-svn: 285148
2016-10-26 00:54:03 +00:00
Rafael Espindola 58139d1758 Delete getSectionHdr.
We were fairly inconsistent as to what information should be accessed
with getSectionHdr and what information (like alignment) was stored
elsewhere.

Now all section info has a dedicated getter. The code is also a bit
more compact.

llvm-svn: 285079
2016-10-25 16:14:25 +00:00
Eugene Leviant db35fdf70f Don't include PHDRs if linker script doesn't want them
This script below shouldn't include file and program headers
to PT_LOAD segment, because it doesn't have PHDRS and FILEHDR
attributes:

PHDRS { all PT_LOAD; }
SECTIONS { /* list of sections here */ }

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

llvm-svn: 284709
2016-10-20 09:39:09 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rui Ueyama 7c1381a099 Read an expression in the form of "ABSOLUTE(<expr>) op <expr> ...".
Fixes bug 30741.

llvm-svn: 284662
2016-10-19 23:11:21 +00:00
Eugene Leviant ce30b1c78e [ELF] Choose default segment when it is not specified
Linker scripts may specify PHDRS, but not specify section to
segment assignments, i.e:

PHDRS { seg PT_LOAD; }
SECTIONS { 
  .sec1 {} : seg
  .sec2 {} 
}

In such case linker should still choose some segment for .sec2 section.
This patch will add .sec2 to previously opened segments (seg) or to the 
very first PT_LOAD segment, if no section-to-segment assignments has been
made

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

llvm-svn: 284600
2016-10-19 15:04:49 +00:00
George Rimar 95dd718c98 [ELF] - Linkerscript: accept integer values for PHDRS types.
Both gold and ld accepts integers instead of named constants
for PHDRS.
Patch adds support for that.

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

llvm-svn: 284470
2016-10-18 10:49:50 +00:00
Rui Ueyama 83043f237c Rename skip(StringRef) -> consume(StringRef).
skip() and skip(StringRef) were overloaded functions that
have different semantics. This patch rename one of the functions
to avoid function overloading.

llvm-svn: 284396
2016-10-17 16:01:53 +00:00
Justin Bogner 5424e7c7dc ELF: Add a skip() overload to ignore any token
Most functions that return StringRef should check their return values,
so I'm planning on marking StringRef [[nodiscard]]. This requires
splitting up functions like next() that are sometimes just used for
side effects.

llvm-svn: 284363
2016-10-17 06:21:13 +00:00
Justin Bogner 5af1687fd2 ELF: Fix a misuse of Twine::toStringRef
While the toStringRef API almost certainly ends up populating the
SmallString here, the correct way to use this API is to use the return
value.

llvm-svn: 284361
2016-10-17 06:08:48 +00:00
George Rimar 270173f2db [ELF] - Added support of PT_OPENBSD_RANDOMIZE
This is 30646.

PT_OPENBSD_RANDOMIZE
The array element specifies the location and size of a part of the memory image of the program that must be filled with random data before any code in the object is executed. The memory region specified by a segment of this type may overlap the region specified by a PT_GNU_RELRO segment, in which case the intersection will be filled with random data before being marked read-only.

Reference links:
http://man.openbsd.org/OpenBSD-current/man5/elf.5
c494713c45

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

llvm-svn: 284234
2016-10-14 13:02:22 +00:00
George Rimar cc6e567ca3 [ELF] - Implemented -z wxneeded.
-z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED.

PT_OPENBSD_WXNEEDED
The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects.

http://man.openbsd.org/OpenBSD-current/man5/elf.5

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

llvm-svn: 284226
2016-10-14 10:34:36 +00:00
Rui Ueyama 05384080df Support GNU-style ZLIB-compressed input sections.
Previously, we supported only SHF_COMPRESSED sections because it's
new and it's the ELF standard. But there are object files compressed
in the GNU style out there, so we had to support it.

Sections compressed in the GNU style start with ".zdebug_" and
contain different headers than the ELF standard's one. In this
patch, getRawCompressedData is responsible to handle it.

A tricky thing about GNU-style compressed sections is that we have
to rename them when creating output sections. ".zdebug_" prefix
implies the section is compressed. We need to rename ".zdebug_"
".debug" because our output sections are not compressed.
We do that in this patch.

llvm-svn: 284068
2016-10-12 22:36:31 +00:00
Eugene Leviant cc1ba8c7d0 Alternative fix for reloc tareting discarded section
r283984 introduced a problem of too many warning messages being shown
when -ffunction-sections and -fdata-sections were used in conjunction 
with --gc-sections linker flag and debugging information present. This
happens because lot of relocations from .debug_line section may become
invalid in such case. The newer fix doesn't show any warning message but
zeroes OutSec pointer in createInputSectionList() to avoid crash, when
relocations are written

llvm-svn: 284010
2016-10-12 12:31:34 +00:00
Rui Ueyama b224c048b4 Remove trailing whitespace.
llvm-svn: 283786
2016-10-10 18:10:01 +00:00
Eugene Leviant cd8eaf891a [ELF] Don't emit empty PT_LOAD segment
Sometimes the very first PT_LOAD segment, created by lld, can be empty. 
This happens when (all conditions met):

- Linker script is used
- First section in ELF image is not RO
- Not enough space for program headers.

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

llvm-svn: 283760
2016-10-10 15:09:44 +00:00
Eugene Leviant 9257764d61 [ELF] Change argument type for findSections. NFC
llvm-svn: 283742
2016-10-10 11:23:12 +00:00
Eugene Leviant b71d6f7a72 [ELF] Linker script: implement LOADADDR
Differential revision: https://reviews.llvm.org/D24298

llvm-svn: 283429
2016-10-06 09:39:28 +00:00
Rui Ueyama b66260ac17 Remove trailing whitespace.
llvm-svn: 283372
2016-10-05 20:09:50 +00:00
Eugene Leviant a8d12ef853 Do not join sections for relocatable object files
Differential revision: https://reviews.llvm.org/D25232

llvm-svn: 283307
2016-10-05 10:10:45 +00:00
Eugene Leviant cf43f179b1 [ELF] make KEEP command recognize file patterns
Differential revision: https://reviews.llvm.org/D25242

llvm-svn: 283305
2016-10-05 09:36:59 +00:00
Rafael Espindola be6073345e Start linker scripts at 0.
We were implicitly creating space for the headers. That is not the
behaviour of bfd, which requires the script to use SIZEOF_HEADERS. The
difference is important for scripts that don't use SIZEOF_HEADERS and
expect the first section to be at 0.

llvm-svn: 282818
2016-09-30 00:16:11 +00:00
Rafael Espindola 6d91fce526 Don't error if we can't put the header in a PT_LOAD.
If there is not sufficient address space, just give up and don't put
the header in the PT_LOAD.

This matches bfd behaviour and I found at least one script that
depends on having a section at address 0.

llvm-svn: 282750
2016-09-29 18:50:34 +00:00
Petr Hosek 997f8838e5 [ELF] Support -z max-page-size option
This options issupported by both BFD ld and gold and allows
overriding the max page size whose default values are defined by
the target.

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

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

llvm-svn: 282596
2016-09-28 15:20:47 +00:00
George Rimar e38cbab5a4 [ELF] - Linkerscript: implemented BYTE/SHORT/LONG/QUAD commands.
The BYTE, SHORT, LONG, and QUAD commands store one, two, four, and eight bytes (respectively). 
After storing the bytes, the location counter is incremented by the number of bytes
stored.

Previously our scripts handles these commands incorrectly. For example:
SECTIONS  {
  .foo : {
 *(.foo.1)
 BYTE(0x11)
...
We accepted the script above treating BYTE as input section description. 
These commands are used in the wild though.

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

llvm-svn: 282429
2016-09-26 19:22:50 +00:00
George Rimar f28210285b [ELF] - Format. NFC.
llvm-svn: 282395
2016-09-26 11:00:48 +00:00
Rui Ueyama 9c4ac5f26c Combine two StringSwitch::Cases because Cases now can take 6 parameters.
llvm-svn: 282307
2016-09-23 22:22:34 +00:00