aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/ScriptParser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-11-25[ELF] Rename BaseCommand to SectionCommand. NFCFangrui Song1-8/+8
BaseCommand was picked when PHDRS/INSERT/etc were not implemented. Rename it to SectionCommand to match `sectionCommands` and make it clear that the commands are used in SECTIONS (except a special case for SymbolAssignment). Also, improve naming of some BaseCommand variables (base -> cmd).
2021-11-25[ELF] Rename OutputSection::sectionCommands to commands. NFCFangrui Song1-5/+5
This partially reverts r315409: the description applies to LinkerScript, but not to OutputSection. The name "sectionCommands" is used in both LinkerScript::sectionCommands and OutputSection::sectionCommands, which may lead to confusion. "commands" in OutputSection has no ambiguity because there are no other types of commands.
2021-11-24[ELF] Support the "read-only" memory region attributeIgor Kudrin1-18/+26
The attribute 'r' allows (or disallows for the negative case) read-only sections, i.e. ones without the SHF_WRITE flag, to be assigned to the memory region. Before the patch, lld could put a section in the wrong region or fail with "error: no memory region specified for section". Differential Revision: https://reviews.llvm.org/D113771
2021-10-25[ELF] Update comments/diagnostics for some long options to use the canonical ↵Fangrui Song1-1/+1
two-dash form Rewrite some comments as appropriate.
2021-09-27[ELF] Support symbol names with space in linker script expressionsFangrui Song1-2/+3
Fix PR51961 Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D110490
2021-08-04[ELF] Apply version script patterns to non-default version symbolsFangrui Song1-5/+4
Currently version script patterns are ignored for .symver produced non-default version (single @) symbols. This makes such symbols not localizable by `local:`, e.g. ``` .symver foo3_v1,foo3@v1 .globl foo_v1 foo3_v1: ld.lld --version-script=a.ver -shared a.o ``` This patch adds the support: * Move `config->versionDefinitions[VER_NDX_LOCAL].patterns` to `config->versionDefinitions[versionId].localPatterns` * Rename `config->versionDefinitions[versionId].patterns` to `config->versionDefinitions[versionId].nonLocalPatterns` * Allow `findAllByVersion` to find non-default version symbols when `includeNonDefault` is true. (Note: `symtab` keys do not have `@@`) * Make each pattern check both the unversioned `pat.name` and the versioned `${pat.name}@${v.name}` * `localPatterns` can localize `${pat.name}@${v.name}`. `nonLocalPatterns` can prevent localization by assigning `verdefIndex` (before `parseSymbolVersion`). --- If a user notices new `undefined symbol` errors with a version script containing `local: *;`, the issue is likely due to a missing `global:` pattern. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D107234
2021-08-04Revert "[ELF] Apply version script patterns to non-default version symbols"Fangrui Song1-4/+5
This reverts commit 7ed22a6fa90cbdc70d6806c1121a0c50c1978dce. buf is not cleared so the commit misses some cases.
2021-08-04[ELF] Apply version script patterns to non-default version symbolsFangrui Song1-5/+4
Currently version script patterns are ignored for .symver produced non-default version (single @) symbols. This makes such symbols not localizable by `local:`, e.g. ``` .symver foo3_v1,foo3@v1 .globl foo_v1 foo3_v1: ld.lld --version-script=a.ver -shared a.o # In a.out, foo3@v1 is incorrectly exported. ``` This patch adds the support: * Move `config->versionDefinitions[VER_NDX_LOCAL].patterns` to `config->versionDefinitions[versionId].localPatterns` * Rename `config->versionDefinitions[versionId].patterns` to `config->versionDefinitions[versionId].nonLocalPatterns` * Allow `findAllByVersion` to find non-default version symbols when `includeNonDefault` is true. (Note: `symtab` keys do not have `@@`) * Make each pattern check both the unversioned `pat.name` and the versioned `${pat.name}@${v.name}` * `localPatterns` can localize `${pat.name}@${v.name}`. `nonLocalPatterns` can prevent localization by assigning `verdefIndex` (before `parseSymbolVersion`). --- If a user notices new `undefined symbol` errors with a version script containing `local: *;`, the issue is likely due to a missing `global:` pattern. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D107234
2021-07-25[ELF] Support quoted symbols in symbol assignmentsFangrui Song1-1/+3
glibc/elf/tst-absolute-zero-lib.lds uses `"absolute" = 0;`
2021-06-30[ELF] Preserve section order within an INSERT AFTER commandFangrui Song1-1/+4
For ``` SECTIONS { text.0 : {} text.1 : {} text.2 : {} } INSERT AFTER .data; ``` the current order is `.data text.2 text.1 text.0`. It makes more sense to preserve the specified order and thus improve compatibility with GNU ld. For ``` SECTIONS { text.0 : {} } INSERT AFTER .data; SECTIONS { text.3 : {} } INSERT AFTER .data; ``` GNU ld somehow collects sections with `INSERT AFTER .data` together (IMO inconsistent) but I think it makes more sense to execute the commands in order and get `.data text.3 text.0` instead. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D105158
2021-06-25[ELF] --sysroot: change sysrooted script to not fall back for an absolute pathFangrui Song1-3/+4
Modify the D13209 logic: for a script inside the sysroot, if an absolute path does not exist, report an error instead of falling back to the path without the sysroot prefix. This matches GNU ld, which makes sense to me: we don't want to find an arbitrary file in the host. Reviewed By: ikudrin Differential Revision: https://reviews.llvm.org/D104894
2021-06-25[lld] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-4/+4
2021-06-13[ELF] Add OVERWRITE_SECTIONS commandFangrui Song1-1/+10
This implements https://sourceware.org/bugzilla/show_bug.cgi?id=26404 An `OVERWRITE_SECTIONS` command is a `SECTIONS` variant which contains several output section descriptions. The output sections do not have specify an order. Similar to `INSERT [BEFORE|AFTER]`, `LinkerScript::hasSectionsCommand` is not set, so the built-in rules (see `docs/ELF/linker_script.rst`) still apply. `OVERWRITE_SECTIONS` can be more convenient than `INSERT` because it does not need an anchor section. The initial syntax is intentionally narrow to facilitate backward compatible extensions in the future. Symbol assignments cannot be used. This feature is versatile. To list a few usage: * Use `section : { KEEP(...) }` to retain input sections under GC * Define encapsulation symbols (start/end) for an output section * Use `section : ALIGN(...) : { ... }` to overalign an output section (similar to ld64 `-sectalign`) When an output section is specified by both `OVERWRITE_SECTIONS` and `INSERT`, `INSERT` is processed after overwrite sections. To make this work, this patch changes `InsertCommand` to use name based matching instead of pointer based matching. (This may cause a difference when `INSERT` moves one output section more than once. Such duplicate commands should not be used in practice (seems that in GNU ld the output sections may just disappear).) A linker script can be used without -T/--script. The traditional `SECTIONS` commands are concatenated, so a wrong rule can be more noticeable from the section order. This feature if misused can be less noticeable, just like `INSERT`. Differential Revision: https://reviews.llvm.org/D103303
2021-03-11[ELF] Support . and $ in symbol names in expressionsFangrui Song1-1/+8
GNU ld supports `.` and `$` in symbol names while LLD doesn't support them in `readPrimary` expressions. Using `.` can result in such an error: ``` https://github.com/ClangBuiltLinux/linux/issues/1318 ld.lld: error: ./arch/powerpc/kernel/vmlinux.lds:255: malformed number: .TOC. >>> __toc_ptr = (DEFINED (.TOC.) ? .TOC. : ADDR (.got)) + 0x8000; ``` Allow `.` (ppc64 special symbol `.TOC.`) and `$` (RISC-V special symbol `__global_pointer$`). Change `diag[3-5].test` to use an invalid character `^`. Note: GNU ld allows `~` in non-leading positions of a symbol name. `~` is not used in practice, conflicts with the unary operator, and can cause some parsing difficulty, so this patch does not add it. Differential Revision: https://reviews.llvm.org/D98306
2021-02-08[ELF] Inspect -EL & -EB for OUTPUT_FORMAT(default, big, little)Fangrui Song1-11/+16
Choose big if -EB is specified, little if -EL is specified, or default if neither is specified. The new behavior matches GNU ld. Fixes: https://github.com/ClangBuiltLinux/linux/issues/1025 Differential Revision: https://reviews.llvm.org/D96214
2021-02-08[ELF] Support aarch64_beFangrui Song1-0/+1
This patch adds * Big-endian values for `R_AARCH64_{ABS,PREL}{16,32,64}` and `R_AARCH64_PLT32` * aarch64elfb & aarch64linuxb BFD emulations * elf64-bigaarch64 output format (bfdname) Link: https://github.com/ClangBuiltLinux/linux/issues/1288 Differential Revision: https://reviews.llvm.org/D96188
2021-01-02[PowerPC] Support powerpcle target in LLD [4/5]Brandon Bergren1-0/+1
Add support for linking powerpcle code in LLD. Rewrite lld/test/ELF/emulation-ppc.s to use a shared check block and add powerpcle tests. Update tests. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D93917
2020-12-14lld/ELF: Parse MSP430 BFD/emulation namesLemonBoy1-0/+3
Follow the naming set by TI's own GCC-based toolchain. Also, force the `osabi` field to `ELFOSABI_STANDALONE`, this matches GNU LD's output (the patching is done in `elf32_msp430_post_process_headers`). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D92931
2020-11-12[ELF] Support multiple SORT in an input section descriptionFangrui Song1-10/+19
The second `SORT` in `*(SORT(...) SORT(...))` is incorrectly parsed as a file pattern. Fix the bug by stopping at `SORT*` in `readInputSectionsList`. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D91180
2020-11-10[lld][ELF] Add additional time trace categoriesJames Henderson1-0/+7
I noticed when running a large link with the --time-trace option that there were several areas which were missing any specific time trace categories (aside from the generic link/ExecuteLinker categories). This patch adds new categories to fill most of the "gaps", or to provide more detail than was previously provided. Reviewed by: MaskRay, grimar, russell.gallop Differential Revision: https://reviews.llvm.org/D90686
2020-07-28[lld][linkerscript] Fix handling of DEFINED.Hafiz Abid Qadeer1-1/+4
Current implementation did not check that symbols is actually defined. Only checked for presence. GNU ld documentation says, "Return 1 if symbol is in the linker global symbol table and is defined before the statement using DEFINED in the script, otherwise return 0." https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D83758
2020-07-27[lld][ELF] Add LOG2CEIL builtin ldscript functionIsaac Richter1-0/+10
This patch adds support for the LOG2CEIL builtin function in linker scripts: https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#index-LOG2CEIL_0028exp_0029 As documented for LD, and to keep compatibility, LOG2CEIL(0) returns 0 (not -inf). The test vectors are somewhat arbitrary. We check minimum values (0-4); middle values (2^32, and 2^32+1); and the maximum value (2^64-1). The checks for LOG2CEIL explicitly use full 64-bit values (16 hex digits). This is needed to properly verify that -inf and other interesting results aren't returned. (For some reason, all other tests in operators.test use only 14 digits.) Differential revision: https://reviews.llvm.org/D84054
2020-06-17[ELF] Improve --export-dynamic-symbol performance by checking whether ↵Fangrui Song1-1/+1
wildcard is really used A hasWildcard pattern iterates over symVector, which can be slow when there are many --export-dynamic-symbol. In optimistic cases, most patterns don't use a wildcard character. hasWildcard: false can avoid a symbol table iteration. While here, add two tests using `[` and `?`, respectively.
2020-06-01[ELF] Refine --export-dynamic-symbol semantics to be compatible GNU ld 2.35Fangrui Song1-1/+0
GNU ld from binutils 2.35 onwards will likely support --export-dynamic-symbol but with different semantics. https://sourceware.org/pipermail/binutils/2020-May/111302.html Differences: 1. -export-dynamic-symbol is not supported 2. --export-dynamic-symbol takes a glob argument 3. --export-dynamic-symbol can suppress binding the references to the definition within the shared object if (-Bsymbolic or -Bsymbolic-functions) 4. --export-dynamic-symbol does not imply -u I don't think the first three points can affect any user. For the fourth point, Not implying -u can lead to some archive members unfetched. Add -u foo to restore the previous behavior. Exact semantics: * -no-pie or -pie: matched non-local defined symbols will be added to the dynamic symbol table. * -shared: matched non-local STV_DEFAULT symbols will not be bound to definitions within the shared object even if they would otherwise be due to -Bsymbolic, -Bsymbolic-functions, or --dynamic-list. Reviewed By: psmith Differential Revision: https://reviews.llvm.org/D80487
2020-05-15[ELF] Use namespace qualifiers (lld:: or elf::) instead of `namespace lld { ↵Fangrui Song1-10/+9
namespace elf {` Similar to D74882. This reverts much code from commit bd8cfe65f5fee4ad573adc2172359c9552e8cdc0 (D68323) and fixes some problems before D68323. Sorry for the churn but D68323 was a mistake. Namespace qualifiers avoid bugs where the definition does not match the declaration from the header. See https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions (D74515) Differential Revision: https://reviews.llvm.org/D79982
2020-04-22[ELF] For relative paths in INPUT() and GROUP(), search the directory of the ↵Fangrui Song1-6/+24
current linker script before searching other paths For a relative path in INPUT() or GROUP(), this patch changes the search order by adding the directory of the current linker script. The new search order (consistent with GNU ld >= 2.35 regarding the new test `test/ELF/input-relative.s`): 1. the directory of the current linker script (GNU ld from Binutils 2.35 onwards; https://sourceware.org/bugzilla/show_bug.cgi?id=25806) 2. the current working directory 3. library paths (-L) This behavior makes it convenient to replace a .so or .a with a linker script with additional input. For example, glibc ``` % cat /usr/lib/x86_64-linux-gnu/libm.a /* GNU ld script */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /usr/lib/x86_64-linux-gnu/libm-2.29.a /usr/lib/x86_64-linux-gnu/libmvec.a ) ``` could be simplified as `GROUP(libm-2.29.a libmvec.a)`. Another example is to make libc++.a a linker script: ``` INPUT(libc++.a.1 libc++abi.a) ``` Note, -l is not affected. Reviewed By: psmith Differential Revision: https://reviews.llvm.org/D77779
2020-04-17[ELF] Support a few more SPARCv9 relocationsLemonBoy1-0/+1
Implemented a bunch of relocations found in binaries with medium/large code model and the Local-Exec TLS model. The binaries link and run fine in Qemu. In addition, the emulation `elf64_sparc` is now recognized. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D77672
2020-03-28[lld][ELF] Mark empty NOLOAD output sections SHT_NOBITS instead of SHT_PROGBITSMatt Schulte1-0/+1
This fixes PR# 45336. Output sections described in a linker script as NOLOAD with no input sections would be marked as SHT_PROGBITS. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D76981
2020-03-19[ELF] Create readonly PT_LOAD in the presence of a SECTIONS commandFangrui Song1-6/+0
This essentially drops the change by r288021 (discussed with Georgii Rymar and Peter Smith and noted down in the release note of lld 10). GNU ld>=2.31 enables -z separate-code by default for Linux x86. By default (in the absence of a PHDRS command) a readonly PT_LOAD is created, which is different from its traditional behavior. Not emulating GNU ld's traditional behavior is good for us because it improves code consistency (we create a readonly PT_LOAD in the absence of a SECTIONS command). Users can add --no-rosegment to restore the previous behavior (combined readonly and read-executable sections in a single RX PT_LOAD).
2020-03-19[LLD][ELF] - Disambiguate "=fillexp" with a primary expression to allow ↵Georgii Rymar1-3/+6
=0x90 /DISCARD/ Fixes https://bugs.llvm.org/show_bug.cgi?id=44903 It is about the following case: ``` SECTIONS { .foo : { *(.foo) } =0x90909090 /DISCARD/ : { *(.bar) } } ``` Here while parsing the fill expression we treated the "/" of "/DISCARD/" as operator. With this change, suggested by Fangrui Song, we do not allow expressions with operators (e.g. "0x1100 + 0x22") that are not wrapped into round brackets. It should not be an issue for users, but helps to resolve parsing ambiguity. Differential revision: https://reviews.llvm.org/D74687
2020-03-12[ELF] Correct error message when OUTPUT_FORMAT is usedShoaib Meenai1-3/+3
Any OUTPUT_FORMAT in a linker script overrides the emulation passed on the command line, so record the passed bfdname and use that in the error message about incompatible input files. This prevents confusing error messages. For example, if you explicitly pass `-m elf_x86_64` to LLD but accidentally include a linker script which sets `OUTPUT_FORMAT(elf32-i386)`, LLD would previously complain about your input files being compatible with elf_x86_64, which isn't the actual issue, and is confusing because the input files are in fact x86-64 ELF files. Interestingly enough, this also prevents a segfault! When we don't pass `-m` and we have an object file which is incompatible with the `OUTPUT_FORMAT` set by a linker script, the object file is checked for compatibility before it's added to the objectFiles vector. config->emulation, objectFiles, and sharedFiles will all be empty, so we'll attempt to access bitcodeFiles[0], but bitcodeFiles is also empty, so we'll segfault. This commit prevents the segfault by adding OUTPUT_FORMAT as a possible source of machine configuration, and it also adds an llvm_unreachable to diagnose similar issues in the future. Differential Revision: https://reviews.llvm.org/D76109
2020-03-09[ELF] Postpone evaluation of ORIGIN/LENGTH in a MEMORY commandFangrui Song1-9/+9
``` createFiles(args) readDefsym readerLinkerScript(*mb) ... readMemory readMemoryAssignment("ORIGIN", "org", "o") // eagerly evaluated target = getTarget(); link(args) writeResult<ELFT>() ... finalizeSections() script->processSymbolAssignments() addSymbol(cmd) // with this patch, evaluated here ``` readMemoryAssignment eagerly evaluates ORIGIN/LENGTH and returns an uint64_t. This patch postpones the evaluation to make * --defsym and symbol assignments * `CONSTANT(COMMONPAGESIZE)` (requires a non-null `lld::elf::target`) work. If the expression somehow requires interaction with memory regions, the circular dependency may cause the expression to evaluate to a strange value. See the new test added to memory-err.s Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D75763
2020-02-12[ELF] Support INSERT [AFTER|BEFORE] for orphan sectionsFangrui Song1-19/+19
D43468+D44380 added INSERT [AFTER|BEFORE] for non-orphan sections. This patch makes INSERT work for orphan sections as well. `SECTIONS {...} INSERT [AFTER|BEFORE] .foo` does not set `hasSectionCommands`, so the result will be similar to a regular link without a linker script. The differences when `hasSectionCommands` is set include: * image base is different * -z noseparate-code/-z noseparate-loadable-segments are unavailable * some special symbols such as `_end _etext _edata` are not defined The behavior is similar to GNU ld: INSERT is not considered an external linker script. This feature makes the section layout more flexible. It can be used to: * Place .nv_fatbin before other readonly SHT_PROGBITS sections to mitigate relocation overflows. * Disturb the layout to expose address sensitive application bugs. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D74375
2020-02-08[ELF] Simplify parsing of version dependency. NFCFangrui Song1-3/+2
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+2
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-22[lld/ELF] PR44498: Support input filename in double quoteThomas Preud'homme1-8/+9
Summary: Linker scripts allow filenames to be put in double quotes to prevent characters in filenames that are part of the linker script syntax from having their special meaning. Case in point the * wildcard character. Availability of double quoting filenames also allows to fix a failure in ELF/linkerscript/filename-spec.s when the path contain a @ which the lexer consider as a special characters and thus break up a filename containing it. This may happens under Jenkins which createspath such as pipeline@2. To avoid the need for escaping GlobPattern metacharacters in filename in double quotes, GlobPattern::create is augmented with a new parameter to request literal matching instead of relying on the presence of a wildcard character in the pattern. Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap Reviewed By: MaskRay Subscribers: peter.smith, grimar, ruiu, emaste, arichardson, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72517
2020-01-21[LLD][ELF] Add support for INPUT_SECTION_FLAGSPeter Smith1-9/+88
The INPUT_SECTION_FLAGS linker script command is used to constrain the section pattern matching to sections that match certain combinations of flags. There are two ways to express the constraint. withFlags: Section must have these flags. withoutFlags: Section must not have these flags. The syntax of the command is: INPUT_SECTION_FLAGS '(' sect_flag_list ')' sect_flag_list: NAME | sect_flag_list '&' NAME Where NAME matches a section flag name such as SHF_EXECINSTR, or the integer value of a section flag. If the first character of NAME is ! then it means must not contain flag. We do not support the rare case of { INPUT_SECTION_FLAGS(flags) filespec } where filespec has no input section description like (.text). As an example from the ld man page: SECTIONS { .text : { INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) } .text2 : { INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) } } .text will match sections called .text that have both the SHF_MERGE and SHF_STRINGS flag. .text2 will match sections called .text that don't have the SHF_WRITE flag. The flag names accepted are the generic to all targets and SHF_ARM_PURECODE as it is very useful to filter all the pure code sections into a single program header that can be marked execute never. fixes PR44265 Differential Revision: https://reviews.llvm.org/D72756
2019-10-07[ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song1-9/+10
This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
2019-09-06[ELF] Replace error() with errorOrWarn() for the ASSERT commandFangrui Song1-1/+1
Summary: ld.bfd produces an output with --noinhibit-exec when an ASSERT fails. Use errorOrWarn() so that we can produce an output as well. An interesting case is that symbol assignments may execute multiple times, so we probably want to suppress errors for non-final runs. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D67285 llvm-svn: 371225
2019-08-05[ELF] Consistently prioritize non-* wildcards overs "*" in version scriptsFangrui Song1-22/+8
We prioritize non-* wildcards overs VER_NDX_LOCAL/VER_NDX_GLOBAL "*". This patch generalizes the rule to "*" of other versions and thus fixes PR40176. I don't feel strongly about this GNU linkers' behavior but the generalization simplifies code. Delete `config->defaultSymbolVersion` which was used to special case VER_NDX_LOCAL/VER_NDX_GLOBAL "*". In `SymbolTable::scanVersionScript`, custom versions are handled the same way as VER_NDX_LOCAL/VER_NDX_GLOBAL. So merge `config->versionScript{Locals,Globals}` into `config->versionDefinitions`. Overall this seems to simplify the code. In `SymbolTable::assign{Exact,Wildcard}Versions`, `sym->verdefIndex == config->defaultSymbolVersion` is changed to `verdefIndex == UINT32_C(-1)`. This allows us to give duplicate assignment diagnostics for `{ global: foo; };` `V1 { global: foo; };` In test/linkerscript/version-script.s: vs_index of an undefined symbol changes from 0 to 1. This doesn't matter (arguably 1 is better because the binding is STB_GLOBAL) because vs_index of an undefined symbol is ignored. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D65716 llvm-svn: 367869
2019-07-16Fix parameter name comments using clang-tidy. NFC.Rui Ueyama1-6/+6
This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
2019-07-11[Coding style change][lld] Rename variables for non-ELF portsRui Ueyama1-3/+3
This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
2019-07-10[LLD][ELF] - Linkerscript: fix FILL() expressions handling.George Rimar1-0/+2
D64130 introduced a bug described in the following message: https://reviews.llvm.org/D64130#1571560 The problem can happen with the following script: SECTIONS { .out : { ... FILL(0x10101010) *(.aaa) ... } The current code tries to read (0x10101010) as an expression and does not break when meets *, what results in a script parsing error. In this patch, I verify that FILL command's expression always wrapped in (). And at the same time =<fillexp> expression can be both wrapped or unwrapped. I checked it matches to bfd/gold. Differential revision: https://reviews.llvm.org/D64476 llvm-svn: 365635
2019-07-10[Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama1-609/+609
letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
2019-07-04[LLD][ELF] - Linkerscript: add a support for expressions for section's fillingGeorge Rimar1-23/+17
Imagine the script: .section: { ... } = FILL_EXPR LLD assumes that FILL_EXPR is a number, and does not allow it to be an expression. Though that is allowed by specification: https://sourceware.org/binutils/docs-2.32/ld/Output-Section-Fill.html This patch adds a support for cases when FILL_EXPR is simple math expression. Fixes https://bugs.llvm.org/show_bug.cgi?id=42482. Differential revision: https://reviews.llvm.org/D64130 llvm-svn: 365143
2019-07-03Avoid identifiers that are different only in case. NFC.Rui Ueyama1-17/+15
Some variables in lld have the same name as functions ignoring case. This patch gives them different names, so that my next patch is easier to read. llvm-svn: 365003
2019-06-10[ELF][RISCV] Parse BFD names elf{32,64}-littleriscvFangrui Song1-0/+2
e.g. glibc libc.so on riscv64 uses `OUTPUT_FORMAT(elf64-littleriscv)`. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D63070 llvm-svn: 362922
2019-05-13[ELF] Full support for -n (--nmagic) and -N (--omagic) via common pagePeter Smith1-1/+1
The -n (--nmagic) disables page alignment, and acts as a -Bstatic The -N (--omagic) does what -n does but also marks the executable segment as writeable. As page alignment is disabled headers are not allocated unless explicit in the linker script. To disable page alignment in LLD we choose to set the page sizes to 1 so that any alignment based on the page size does nothing. To set the Target->PageSize to 1 we implement -z common-page-size, which has the side effect of allowing the user to set the value as well. Setting the page alignments to 1 does mean that any use of CONSTANT(MAXPAGESIZE) or CONSTANT(COMMONPAGESIZE) in a linker script will return 1, unlike in ld.bfd. However given that -n and -N disable paging these probably shouldn't be used in a linker script where -n or -N is in use. Differential Revision: https://reviews.llvm.org/D61688 llvm-svn: 360593
2019-04-26[LLD][ELF] - Do not remove empty sections referenced in LOADADDR/ADDR commands.George Rimar1-0/+2
This is https://bugs.llvm.org//show_bug.cgi?id=38750. If script references empty sections in LOADADDR/ADDR commands .empty : { *(.empty ) } .text : AT(LOADADDR (.empty) + SIZEOF (.empty)) { *(.text) } then an empty section will be removed and LOADADDR/ADDR will evaluate to null. It is not that user may expect from using of the generic script, what is a common case. Differential revision: https://reviews.llvm.org/D54621 llvm-svn: 359279
2019-04-24[ELF] Delete a redundant SHT_NOBITS -> SHT_PROGBITS after D60131Fangrui Song1-1/+0
Differential Revision: https://reviews.llvm.org/D61006 llvm-svn: 359099