Commit Graph

9321 Commits

Author SHA1 Message Date
George Rimar 81eca18df3 [ELF] - Linkerscript: Add `~` as separate math token.
Previously we did not support following:
foo = ~0xFF;
and had to add space before numeric value:
foo = ~ 0xFF

That was constistent with ld.bfd < 2.30, which shows:
script.txt:3: undefined symbol `~2' referenced in expression,
but inconsistent with gold.

It was fixed for ld.bfd 2.30 as well:
https://sourceware.org/bugzilla/show_bug.cgi?id=22267

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

llvm-svn: 315569
2017-10-12 08:40:12 +00:00
Martin Storsjo a84a47741a [MinGW] Hook up the --export-all-symbols and --output-def options
Differential Revision: https://reviews.llvm.org/D38761

llvm-svn: 315563
2017-10-12 05:37:18 +00:00
Martin Storsjo 7f71acdcd7 [COFF] Add support for automatically exporting all symbols
GNU ld automatically exports all symbols if no symbols have
been chosen to export via either def files or dllexport attributes.
The same behaviour can also be enabled via the GNU ld option
--export-all-symbols, in case some symbols are marked for export
via a def file or dllexport attribute.

The list of excluded symbols is from GNU ld, minus the
cygwin specific symbols.

Also add support for outputting the actual list of exported
symbols in a def file, as in the GNU ld option --output-def.

These options in GNU ld are documented in
https://sourceware.org/binutils/docs/ld/WIN32.html.

This currently exports all symbols from object files pulled in
from libmingw32 and libmingwex and other static libraries
that are linked in.

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

llvm-svn: 315562
2017-10-12 05:37:13 +00:00
Martin Storsjo ea460a2d0c [COFF] Implement support for IMAGE_REL_ARM64_ADDR32NB
This is implemented in the same way as the other ADDR32NB relocations
for ARM and X64.

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

llvm-svn: 315561
2017-10-12 05:37:06 +00:00
Rui Ueyama cd063a9c7a Start destructuring adjustExpr function.
adjustExpr became a mysterious function as it does too many things.
This patch is an attempt to destructure that function.

llvm-svn: 315560
2017-10-12 05:32:52 +00:00
Rui Ueyama 3427c696f1 Fix comment.
llvm-svn: 315559
2017-10-12 04:52:54 +00:00
Rui Ueyama b518f655c3 Move more code out of scanRelocs().
llvm-svn: 315558
2017-10-12 04:52:39 +00:00
Rui Ueyama bf26e4e2a2 Make a function shorter.
llvm-svn: 315555
2017-10-12 04:02:02 +00:00
Rui Ueyama be85529d2b Remove one parameter from Target::getRelExpr.
A section was passed to getRelExpr just to create an error message.
But if there's an invalid relocation, we would eventually report it
in relocateOne. So we don't have to pass a section to getRelExpr.

llvm-svn: 315552
2017-10-12 03:14:06 +00:00
Rui Ueyama 63e49d489b Rewrite comment.
llvm-svn: 315548
2017-10-12 02:09:11 +00:00
Rui Ueyama 36d8db42d8 Rename P -> Pieces.
Conventionally, an array of SectionPieces is named Pieces.
It is better to follow the convention.

llvm-svn: 315543
2017-10-12 00:43:22 +00:00
NAKAMURA Takumi b6d3452243 lld: Prune unused libdeps.
llvm-svn: 315537
2017-10-12 00:04:24 +00:00
NAKAMURA Takumi d791eaa559 lld: Reorder libdeps.
Differential Revision: https://reviews.llvm.org/D38828

llvm-svn: 315529
2017-10-11 23:18:43 +00:00
Rui Ueyama 67533a2cb3 Define RelType to represent relocation types.
We were using uint32_t as the type of relocation kind. It has a
readability issue because what Type really means in `uint32_t Type`
is not obvious. It could be a section type, a symbol type or a
relocation type.

Since we do not do any arithemetic operations on relocation types
(e.g. adding one to R_X86_64_PC32 doesn't make sense), it would be
more natural if they are represented as enums. Unfortunately, that
is not doable because relocation type definitions are spread into
multiple header files.

So I decided to use typedef. This still should be better than the
plain uint32_t because the intended type is now obvious.

llvm-svn: 315525
2017-10-11 22:49:24 +00:00
Rui Ueyama 4092016b7b Return early if it fails to parse a hex string.
This patch doesn't change the behavior of the program because it
would eventually return None at end of the function. But it is
better to return None early if we know it will eventually happen.

llvm-svn: 315495
2017-10-11 19:30:39 +00:00
Davide Italiano db710f28e6 [ELF] Try to not emit weird diagnostics on undefined symbols.
Fixes PR34872.

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

llvm-svn: 315487
2017-10-11 18:37:24 +00:00
Rafael Espindola 329886556a Update for llvm change.
llvm-svn: 315478
2017-10-11 17:23:29 +00:00
George Rimar 970e783bdd [ELF] - Fix out of sync comment. NFC.
llvm-svn: 315442
2017-10-11 08:18:53 +00:00
George Rimar 26fa916deb [ELF] - Do not set output section flags except SHF_{ALLOC,WRITE,EXECINSTR}.
This is PR34546.

Currently LLD creates output sections even if it has no input sections,
but its command contains an assignment.
Committed code just assigns the same flag that was used in previous
live section.
That does not work sometimes. For example if we have following script:

.ARM.exidx : { *(.ARM.exidx*) }
.foo : { _foo = 0; } }
Then first section has SHF_LINK_ORDER flag. But section foo should not.
That was a reason of crash in OutputSection::finalize(). LLD tried to calculate
Link value, calling front() on empty input sections list.
We should only keep access flags and omit all others when creating such sections.

Patch fixes the crash observed.

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

llvm-svn: 315441
2017-10-11 08:13:40 +00:00
Rui Ueyama a2212f846b Do not copy Sections vector.
llvm-svn: 315436
2017-10-11 05:13:16 +00:00
Rui Ueyama 7ad1e3102a Split LinkerScript::computeInputSections into two functions.
llvm-svn: 315434
2017-10-11 04:50:30 +00:00
Rui Ueyama 722221f5a7 Swap parameters of getSymbolValue.
Usually, a function that does symbol lookup takes symbol name as
its first argument. Also, if a function takes a source location hint,
it is usually the last parameter. So the previous parameter order
was counter-intuitive.

llvm-svn: 315433
2017-10-11 04:34:34 +00:00
Rui Ueyama f5733500c9 Do not handle DefinedCommon in linker scripts.
Because of r314495, DefinedCommon symbols cannot reach to
getSymbolValue function. When they reach the fucntion, they have
already been converted to DefinedRegular symbols.

llvm-svn: 315432
2017-10-11 04:31:13 +00:00
Rui Ueyama f0403c601a Rename BytesDataCommand -> ByteCommand.
llvm-svn: 315431
2017-10-11 04:22:09 +00:00
Rui Ueyama 2f4c121d89 Inline LinkerScript::process.
"process" was not a good name because everything can be named it.

llvm-svn: 315430
2017-10-11 04:21:55 +00:00
Rui Ueyama 355a8dd663 Split a loop into two to make it clear that it did two different things.
llvm-svn: 315427
2017-10-11 04:01:24 +00:00
Rui Ueyama 0543343170 Use more precise type.
llvm-svn: 315426
2017-10-11 04:01:13 +00:00
Rui Ueyama 187b67a533 Remove a static local varaible.
We should generally avoid static local variables.

llvm-svn: 315425
2017-10-11 03:34:09 +00:00
Rui Ueyama 1f4d7b56f4 Avoid a pointer to a pointer to an input section.
llvm-svn: 315424
2017-10-11 03:23:29 +00:00
Rui Ueyama ec5c4adbf2 Add comment.
llvm-svn: 315423
2017-10-11 03:23:17 +00:00
Rui Ueyama 2b714b56a9 Split decompressAndMergeSection into two separate functions.
Even though they are called sequentially, they are separate
operations, so it is better to split it.

llvm-svn: 315422
2017-10-11 03:12:53 +00:00
Rui Ueyama b801441ed3 Remove useless cast.
llvm-svn: 315421
2017-10-11 02:55:05 +00:00
Rui Ueyama 04c9ca7408 Rename filename -> getFilename.
llvm-svn: 315420
2017-10-11 02:54:52 +00:00
Rui Ueyama 71f840672d Rename Align -> Alignment.
llvm-svn: 315419
2017-10-11 02:46:09 +00:00
Rui Ueyama 29b240c671 Rename CurAddressState -> Ctx.
We used CurAddressState to capture a dynamic context just like
we use lambdas to capture static contexts. So, CurAddressState
is used everywhere in LinkerScript.cpp. It is worth a shorter
name.

llvm-svn: 315418
2017-10-11 02:45:54 +00:00
Rui Ueyama 183aa2731e Make LinkerScript::addSymbol a private member function.
llvm-svn: 315416
2017-10-11 02:28:39 +00:00
Rui Ueyama 5908c2f877 Rename processCommands -> processSectionCommands.
llvm-svn: 315415
2017-10-11 02:28:28 +00:00
Rui Ueyama a80633ca14 Inline small functions.
llvm-svn: 315414
2017-10-11 02:20:00 +00:00
Rui Ueyama 6b394caaf1 Rename Commands -> SectionCommands.
"Commands" was ambiguous because in the linker script, everything is
a command. We used to handle only SECTIONS commands, and at the time,
it might make sense to call them the commands, but it is no longer
the case. We handle not only SECTIONS but also MEMORY, PHDRS, VERSION,
etc., and they are all commands.

llvm-svn: 315409
2017-10-11 01:50:56 +00:00
Rui Ueyama a323e2a722 Rename HasSections -> HasSectionsComand.
HasSections is true if there is at least one SECTIONS linker
script command, and it is not directly related to whether we have
section objects or not. So I think the new name is better.

llvm-svn: 315405
2017-10-11 01:34:51 +00:00
Rui Ueyama 7f1c266e43 Move a loop invariant outside the loop.
llvm-svn: 315404
2017-10-11 01:26:22 +00:00
Rui Ueyama ac27de9dc7 Remove ScriptConfiguration class and move the members to LinkerScript class.
ScriptConfiguration was a class to contain parsed results of
linker scripts. LinkerScript is a class to interpret it.

That ditinction was needed because we haven't instantiated
LinkerScript early (because, IIRC, LinkerScript class was a
ELFT template function). So, when we parse linker scripts,
we couldn't directly store the result to a LinkerScript instance.

Now, that limitation is gone. We instantiate LinkerScript
at the very beginning of our main function. We can directly
store parse results to a LinkerScript instance.

llvm-svn: 315403
2017-10-11 01:19:33 +00:00
Rui Ueyama 18d19687c8 Inline addRegular into addSymbol.
Because addRegular's functionality is tightly coupled with
addSymbol, and the former is called only once, it makes sense
to merge the two functions. This patch also adds comments.

llvm-svn: 315401
2017-10-11 01:03:37 +00:00
Peter Collingbourne 8a40a7b15c COFF: When generating code for LTO, use static reloc model on 32-bit x86.
Fixes PR34306.

This is because it usually results in more compact code, and because
there are also known code generation bugs when using the PIC model
(see bug).

Based on a patch by Carlo Kok.

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

llvm-svn: 315400
2017-10-11 00:46:58 +00:00
Rui Ueyama 4fbe351817 Remove a constructor from ExprValue. NFC.
I think three ctors are too many for this simple class.

llvm-svn: 315394
2017-10-11 00:06:27 +00:00
Rui Ueyama 41ef17bb3c Add comments.
llvm-svn: 315393
2017-10-11 00:01:49 +00:00
Rui Ueyama ed94f36154 Remove an unused default argument.
llvm-svn: 315386
2017-10-10 23:09:23 +00:00
Rui Ueyama a1b79dff2a Handle input section liveness only in MarkLive.cpp.
The condition whether a section is alive or not by default
is becoming increasingly complex, so the decision of garbage
collection is spreading over InputSection.h and MarkLive.cpp,
which is not a good state.

This moves the code to MarkLive.cpp, to keep the file the central
place to make decisions about garbage collection.

llvm-svn: 315384
2017-10-10 22:59:32 +00:00
Rafael Espindola ae5e9ed422 Update for llvm change.
llvm-svn: 315377
2017-10-10 22:18:16 +00:00
Rafael Espindola 97c57b9e7b Don't create a dummy __tls_get_addr.
We just don't need one with the current setup.

We only error on undefined references that are used by some
relocation.

If we managed to relax all uses of __tls_get_addr, no relocation uses
it and we don't produce an error.

This is less code and fixes the case were we fail to relax. Before we
would produce a broken output, but now we produce an error.

llvm-svn: 315334
2017-10-10 17:27:34 +00:00