Commit Graph

104 Commits

Author SHA1 Message Date
George Rimar b91e7118d4 Reformat comment from 3 to 2 lines. NFC.
llvm-svn: 275961
2016-07-19 07:42:07 +00:00
George Rimar 6ad330acaa Fixed comment. NFC.
llvm-svn: 275959
2016-07-19 07:39:07 +00:00
Eugene Leviant 0e36f42846 [ELF] Overriding reserved symbols in linker script
llvm-svn: 275549
2016-07-15 11:20:04 +00:00
Rui Ueyama 177746a739 Remove redundant `return`.
llvm-svn: 275528
2016-07-15 04:32:11 +00:00
Rui Ueyama 05ef4cff44 Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter.
Previously, we had two expression types, ExprKind and SymbolAssignmentKind
for `.` and all the other symbol names, respectively. But we could merge
them because the former is a special case of the latter.

llvm-svn: 275527
2016-07-15 04:19:37 +00:00
Eugene Leviant b030411414 [ELF] r275383 reverted due to buildbot failure
llvm-svn: 275385
2016-07-14 09:21:24 +00:00
Eugene Leviant 219d9b2b18 [ELF] Allow overriding reserved symbols in linker scripts
llvm-svn: 275383
2016-07-14 08:26:41 +00:00
Eugene Leviant eda81a1b86 [ELF] Support for symbol assignment in linker scripts within SECTIONS {} block
llvm-svn: 275158
2016-07-12 06:39:48 +00:00
Rafael Espindola 64c32d6f02 Fix formating. NFC.
llvm-svn: 274757
2016-07-07 14:28:47 +00:00
Rui Ueyama 52c4e17f8a Remove trailing whitespaces.
llvm-svn: 274343
2016-07-01 10:42:25 +00:00
Eugene Leviant 467c4d5538 [ELF] Fix first PT_LOAD segment VA calculation, when linker script is used
llvm-svn: 274342
2016-07-01 10:27:36 +00:00
Rui Ueyama 93c9af425e Create Strings.cpp and move string manipulation functions to that file.
llvm-svn: 274109
2016-06-29 08:01:32 +00:00
Rui Ueyama 722830a51b Rename matchStr -> globMatch.
llvm-svn: 274103
2016-06-29 05:32:09 +00:00
Davide Italiano 8e1131dc46 [ELF] Support for wildcard in version scripts.
Example:

VERSION_1.0 {
  global: foo*;
  local: *; }

now correctly matches all the symbols which name starts with
`foo`.

Differential Revision:  http://reviews.llvm.org/D21732

llvm-svn: 274091
2016-06-29 02:46:51 +00:00
Davide Italiano 47ae3c3e22 [LinkerScript] Spell 'character' correctly. NFC.
llvm-svn: 273817
2016-06-26 19:02:43 +00:00
Rui Ueyama 424b408165 Rename Align -> Alignment.
I think it is me who named these variables, but I always find that
they are slightly confusing because align is a verb.
Adding four letters is worth it.

llvm-svn: 272984
2016-06-17 01:18:46 +00:00
Dima Stepanov fb8978fc6a Fix the function to set the section VMA/LMA fields in case of using
the linker script. The cycle in the ELF/LinkerScript.cpp:assignAddresses()
routine will be used to go through all the sections and set all the
addresses correctly.

Add new test to check this case.

llvm-svn: 270090
2016-05-19 18:15:54 +00:00
George Rimar fbfe10f221 Removed dead code. NFC.
llvm-svn: 268497
2016-05-04 13:44:49 +00:00
George Rimar ab9390664f [ELF] - Implemented comparsion operators for linkerscript.
Patch adds support of <,>,!=,==,>=,<= operators.

Differential revision: http://reviews.llvm.org/D19419

llvm-svn: 267382
2016-04-25 08:14:41 +00:00
Rui Ueyama 9c1112d09a Use ScriptParserBase features to parse linker script expressions.
Previously, we have re-implemented utility functions such as `expect`
or `next` in LinkerScript.cpp. This patch reuses the existing
implementation that is in ScriptParser.cpp.

llvm-svn: 267255
2016-04-23 00:04:03 +00:00
Rui Ueyama 4a46539c24 Devirtualize ScriptParserBase. NFC.
ScriptParserBase class is a container of collection of various methods
to parse linker script-ish text. It had a virtual method `run` to run
the parser. But we don't have to enforce its descendents to implement
that. It's up to them.

This patch removes pure virtual function `run`.

llvm-svn: 267246
2016-04-22 22:59:24 +00:00
Rui Ueyama 5fa60985cf Inline getInteger as it's too short to be a function. NFC.
llvm-svn: 267219
2016-04-22 21:05:04 +00:00
Rui Ueyama e29a975d23 Update a comment for r267145.
llvm-svn: 267218
2016-04-22 21:02:27 +00:00
Rui Ueyama 0b3868ec6b Move uintX_t typedef to the class definition. NFC.
Now it is doable because LinkerScript is a template class.

llvm-svn: 267212
2016-04-22 20:41:07 +00:00
George Rimar dffc1410c5 [ELF] - Implemented linkerscript ALIGN command
ALIGN(exp)
Return the location counter (.) aligned to the next exp boundary. (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html)

Patch implements this command.
This fixes PR27406.

Differential revision: http://reviews.llvm.org/D19364

llvm-svn: 267145
2016-04-22 11:40:53 +00:00
George Rimar fba45c41df Recommitted r267132 "[ELF] - implemented ternary operator for linkerscript expressions"
With fix: removed redundant Dot parameter.

Original commit message:
[ELF] - implemented ternary operator for linkerscript expressions

Patch implements ternary operator for linkerscript expressions.
Like:

SECTIONS {
 . = 0x1 ? 0x2 : 0x3;
...
}

Differential revision: http://reviews.llvm.org/D19332

llvm-svn: 267140
2016-04-22 11:28:54 +00:00
George Rimar f8e230b277 Revert r267132 as it broke buildbot.
llvm-svn: 267134
2016-04-22 10:51:34 +00:00
George Rimar 8c4acddebc [ELF] - implemented ternary operator for linkerscript expressions
Patch implements ternary operator for linkerscript expressions.
Like:

SECTIONS {
 . = 0x1 ? 0x2 : 0x3;
...
}

Differential revision: http://reviews.llvm.org/D19332

llvm-svn: 267132
2016-04-22 10:35:34 +00:00
Rui Ueyama c9f402eadc Inline SectionRule::match.
This short function was used only once and didn't provide much value.

llvm-svn: 267086
2016-04-22 00:23:52 +00:00
Rui Ueyama c998a8c044 ELF: Make the special variable "." as a LinkerScript class member.
I will eventually make `evaluate` function a usual parse function
rather than a function that works on a separate token list.
This is the first step toward that.

llvm-svn: 267083
2016-04-22 00:03:13 +00:00
Rui Ueyama 8ec77e64fc ELF: Change how to handle KEEP linker script command.
You can instruct the linker to not discard sections even if they
are unused and --gc-sections option is given. The linker script
command for doing that is KEEP. The syntax is KEEP(foo) where foo
is a section name. KEEP commands are written in SECTIONS command,
so you can specify the order of sections *and* which sections
will be kept.

Each sub-command in SECTIONS command are translated into SectionRule
object. Previously, each SectionRule has `Keep` bit. However,
if you think about it, this hid information in too deep in elements
of a list. Semantically, KEEP commands aren't really related to
SECTIONS subcommands. We can keep the section list for KEEP in a
separate list. This patch does that.

llvm-svn: 267065
2016-04-21 22:00:51 +00:00
Rui Ueyama c3e2a4b006 ELF: Change the return type of getSectionOrder.
Also changed the function name and added comments.

llvm-svn: 267044
2016-04-21 20:30:00 +00:00
George Rimar dbbd8b15bf [ELF] - Use ArrayRef instead of std::vector& for LinkerScript module. NFC.
llvm-svn: 266978
2016-04-21 11:21:48 +00:00
George Rimar 71b26e94fd [ELF] - Get rid of SectionOrder array.
SectionOrder vector was a part of LinkerScript class.

It can be removed because Commands vector contains the 
same information and SectiorOrder is just a subset.

Differential revision: http://reviews.llvm.org/D19171

llvm-svn: 266974
2016-04-21 10:22:02 +00:00
Rui Ueyama 6011811beb Define and use a utility function. NFC.
llvm-svn: 266914
2016-04-20 20:54:13 +00:00
Rui Ueyama 99e519cdeb ELF: Redefine parseExpr to parse an expression. NFC.
Previously the function reads an operator and the rest of
the expressions. This patch makes it to actually parse an expression
which starts with a primary pexression followed by other expressions
concatenated with operators.

llvm-svn: 266912
2016-04-20 20:48:25 +00:00
Rui Ueyama 07320e4030 ELF: Template LinkerScript class.
Originally, linker scripts were basically an alternative way to specify
options to the command line options. But as we add more features to hanlde
symbols and sections, many member functions needed to be templated.
Now most the members are templated. It is probably time to template the
entire class.

Previously, LinkerScript is an executor of the linker script as well as
a storage of linker script configurations. This is not suitable to template
the class because when we are reading linker script files, we don't know
the ELF type yet, so we can't instantiate ELF-templated classes.

In this patch, I defined a new class, ScriptConfiguration, to store
linker script configurations. ScriptParser writes parse results to it,
and LinkerScript uses them.

Differential Revision: http://reviews.llvm.org/D19302

llvm-svn: 266908
2016-04-20 20:13:41 +00:00
Rui Ueyama 0536ec0242 Make a function file-scoped.
llvm-svn: 266816
2016-04-19 20:50:25 +00:00
Rui Ueyama 7a81d674f6 Attempt to fix buildbot.
llvm-svn: 266799
2016-04-19 19:04:03 +00:00
Rui Ueyama 960504b91d ELF: Add +, -, *, / and & to SECTIONS linker script command.
This patch is based heavily on George Rimor's patch
http://reviews.llvm.org/D19221.

In the linker script, you can write expressions to compute addresses.
Currently we only support "+" operator. This adds a few more operators.

Since this patch adds * and /, we need to handle operator precedences
properly. I implemented that using the operator-precedence grammar.

Differential Revision: http://reviews.llvm.org/D19237

llvm-svn: 266798
2016-04-19 18:58:11 +00:00
Rui Ueyama 9e957a0ac6 Rename LocationNode -> SectionsCommand.
They are called sections-command in the doc, so it is nice to keep
it consistent with it.
https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS

llvm-svn: 266668
2016-04-18 21:00:45 +00:00
Rui Ueyama 54115af45e Remove redundant curly braces.
llvm-svn: 266667
2016-04-18 21:00:43 +00:00
Rui Ueyama 7c18c28c97 Refactor LinkerScript::assignAddresses. NFC.
llvm-svn: 266666
2016-04-18 21:00:40 +00:00
George Rimar 652852c5c0 Recommitted 266457 with fix:
* Do script driven layout only if SECTIONS section exist.

Initial commit message:

[ELF] - Implemented basic location counter support.

This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

Differential revision: http://reviews.llvm.org/D18499

llvm-svn: 266526
2016-04-16 10:10:32 +00:00
Rui Ueyama faac567e68 Revert r266457: "[ELF] - Implemented basic location counter support."
This reverts commit r266457 as it breaks "hello world" both on
Linux and FreeBSD.

llvm-svn: 266485
2016-04-15 22:39:27 +00:00
George Rimar ea25877d4a [ELF] - Implemented basic location counter support.
This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

Differential revision: http://reviews.llvm.org/D18499

llvm-svn: 266457
2016-04-15 17:44:19 +00:00
Adhemerval Zanella e77b5bf69f [lld] [ELF] Add ScriptParserBase class
This patch add a base script tokenizer class to decouple parsing from
linker script handling.  The idea is to use this base class on dynamic
list parsing (--dynamic-list option). No functionality added.

llvm-svn: 265600
2016-04-06 20:59:11 +00:00
George Rimar 2348320d4e [ELF] - Teach linkerscript error handler to show full script line and column marker on error.
When error, this adds the text line of script to the output
and a marks exact incorrect token under it:

line 1: <error text here>
UNKNOWN_TAG {
      ^

Differential revision: http://reviews.llvm.org/D18699

llvm-svn: 265523
2016-04-06 08:08:40 +00:00
Rui Ueyama 38dc83417b Include line number in error message for linker scripts.
This patch is based on http://reviews.llvm.org/D18545 written
by George Rimar.

llvm-svn: 264878
2016-03-30 16:51:57 +00:00
Rui Ueyama 3ed2f06913 Fix spelling.
llvm-svn: 263358
2016-03-13 03:17:44 +00:00