Commit Graph

16 Commits

Author SHA1 Message Date
Fangrui Song 6506907a0a [ELF] Update comments/diagnostics for -defsym and -image-base to use the canonical two-dash form 2021-10-25 14:01:36 -07:00
Fangrui Song 1f69355802 [test] Make ELF tests amenable to the order of non-local symbols 2021-02-12 21:00:42 -08:00
Fangrui Song f0374e7db2 [test] lld/test/: change llvm-objdump single-dash long options to double-dash options 2020-03-15 17:48:36 -07:00
Fangrui Song 71e2ca6e32 [llvm-objdump] -d: print `00000000 <foo>:` instead of `00000000 foo:`
The new behavior matches GNU objdump. A pair of angle brackets makes tests slightly easier.

`.foo:` is not unique and thus cannot be used in a `CHECK-LABEL:` directive.
Without `-LABEL`, the CHECK line can match the `Disassembly of section`
line and causes the next `CHECK-NEXT:` to fail.

```
Disassembly of section .foo:

0000000000001634 .foo:
```

Bdragon: <> has metalinguistic connotation. it just "feels right"

Reviewed By: rupprecht

Differential Revision: https://reviews.llvm.org/D75713
2020-03-05 18:05:28 -08:00
Fangrui Song 81cebfd008 [ELF][test] Change -o %t to -o /dev/null if the output is not needed 2020-02-12 21:54:50 -08:00
Fangrui Song 5387c2cd17 [llvm-objdump] Print newlines before and after "Disassembly of section ...:"
This improves readability and the behavior is consistent with GNU objdump.

The new test test/tools/llvm-objdump/X86/disassemble-section-name.s
checks we print newlines before and after "Disassembly of section ...:"

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

llvm-svn: 359668
2019-05-01 10:40:48 +00:00
Fangrui Song b159906a9a [test] Change llvm-readobj -long-option to --long-option or well-known short options. NFC
Also change some options that have different semantics (cause confusion) in llvm-readelf mode:

-s => -S
-t => --symbols
-sd => --section-data

llvm-svn: 359651
2019-05-01 05:49:01 +00:00
George Rimar c152281632 [LLD][ELF] - Do not crash when parsing the -defsym option from a error state.
When we are in a error state, script parser will not parse the -defsym
expression and hence will not tokenize it. Then ScriptLexer::Pos will be 0
and LLD will assert and crash here:

MemoryBufferRef ScriptLexer::getCurrentMB() {
  assert(!MBs.empty() && Pos > 0); // Bang !

Solution - stop parsing the defsym in a error state. That is consistent
with the regular case (when we parse the linker script).

llvm-svn: 347549
2018-11-26 12:29:56 +00:00
George Rimar 00d6f4bd6b [LLD][ELF] - Fix crash when using empty --defsym.
We have a crash issue when handling the empty -defsym.

For parsing this option we are using ScriptParser class which is used
generally for reading the linker script. For empty defsym case, we
pass the empty memory buffer and crash in the place removed in https://reviews.llvm.org/rL336436.

But reverting of the above patch would not help here (we would still crash but a bit later). And
even after fixing the crash we would report something like
"lld.exe: error: -defsym:1: unexpected EOF"
It is probably not the appropriate message because mentions EOF.

I think the issue should be handled on a higher level like this patch does.
So we do not want to pass the empty memory buffer first of all I believe.

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

llvm-svn: 339412
2018-08-10 06:32:39 +00:00
George Rimar fce824e157 [LLD][ELF] - Add a test case for parsing -defsym.
This adds a coverage for the following line of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L274

llvm-svn: 339326
2018-08-09 10:40:11 +00:00
Petr Hosek 8c7e8cce99 [ELF] Support expressions with -defsym option
Fixes PR34948.

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

llvm-svn: 317396
2017-11-04 02:03:58 +00:00
Rafael Espindola cf00d4374e Fix PR33635.
This is a semantic revert of r306036.

We have to change the names, otherwise dynamic relocations will point
to the wrong name.

llvm-svn: 307110
2017-07-05 00:43:18 +00:00
Rui Ueyama fb02869b74 Remove a stale comment.
llvm-svn: 306295
2017-06-26 15:51:28 +00:00
Rui Ueyama 4402a39981 Keep the original symbol name when renamed.
Previously, when symbol A is renamed B, both A and B end up having
the same name. This is because name is a symbol's attribute, and
we memcpy symbols for symbol renaming.

This pathc saves the original symbol name and restore it after memcpy
to keep the original name.

This patch shouldn't change program's meaning, but names in symbol
tables make more sense than before.

llvm-svn: 306036
2017-06-22 17:30:19 +00:00
George Rimar bb451903f5 [ELF] - Accept --defsym foo=value form.
Previously we accepted --defsym=foo=value only.

Reported by Sean Silva.

llvm-svn: 302227
2017-05-05 11:59:15 +00:00
George Rimar 9703ad2221 [ELF] - Implemented --defsym option.
gnu ld description of option is:

--defsym=symbol=expression
Create a global symbol in the output file, containing the absolute address given 
by expression. You may use this option as many times as necessary to define multiple
symbols in the command line. A limited form of arithmetic is supported for the 
expression in this context: you may give a hexadecimal constant or the name of an
existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or 
symbols. If you need more elaborate expressions, consider using the linker command
language from a script. Note: there should be no white space between symbol, 
the equals sign ("="), and expression.

In compare with D32082, this patch does not support math expressions and absolute
symbols. It implemented via code similar to --wrap. That covers 1 of 3 possible
--defsym cases.

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

llvm-svn: 301391
2017-04-26 10:40:02 +00:00