Commit Graph

13938 Commits

Author SHA1 Message Date
Nico Weber a78fa73bcf Revert "[lld-link] Enable addrsig table in COFF lto"
This reverts commit eabd55b1b2.
Speculative, for crbug.com/1195545
2021-04-03 10:56:33 -04:00
Fangrui Song c318746345 [lld-macho] Fix -Wsuggest-override after D99633. NFC 2021-04-02 17:04:11 -07:00
Jez Ng 817d98d841 [lld-macho][nfc] Refactor in preparation for 32-bit support
The main challenge was handling the different on-disk structures (e.g.
`mach_header` vs `mach_header_64`). I tried to strike a balance between
sprinkling `target->wordSize == 8` checks everywhere (branchy = slow, and ugly)
and templatizing everything (causes code bloat, also ugly). I think I struck a
decent balance by judicious use of type erasure.

Note that LLD-ELF has a similar architecture, though it seems to use more templating.

Linking chromium_framework takes about the same time before and after this
change:

      N           Min           Max        Median           Avg        Stddev
  x  20          4.52          4.67         4.595        4.5945   0.044423204
  +  20           4.5          4.71         4.575         4.582   0.056344803
  No difference proven at 95.0% confidence

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99633
2021-04-02 18:46:39 -04:00
Greg McGary 3f8c6f493b [lld-macho][NFC] Remove redundant member from class Defined
`class Symbol` defines a data member `InputFile *file;`
`class Defined` inherits from `Symbol` and also defines a data member `InputFile *file;` for no apparent purpose.

Differential Revision: https://reviews.llvm.org/D99783
2021-04-02 09:19:15 -07:00
Yang Fan d441dee5c2
[lld][MachO] Fix -Wsign-compare warning (NFC)
GCC warning:
```
/llvm-project/lld/MachO/InputFiles.cpp:484:24: warning: comparison of integer expressions of different signedness: ‘int64_t’ {aka ‘long int’} and ‘uint64_t’ {aka ‘long unsigned int’} [-Wsign-compare]
484 |           return value < subsectionEntry.offset;
    |                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
```
2021-04-02 11:33:56 +08:00
Yang Fan 062d4ddd22
[lld] Add missing header guard (NFC) 2021-04-02 11:12:23 +08:00
Alexander Shaposhnikov f6ad045366 [lld][MachO] Make emitEndFunStab independent from .subsections_via_symbols
This diff addresses FIXME in SyntheticSections.cpp and removes
the dependency of emitEndFunStab on .subsections_via_symbols.

Test plan: make check-lld-macho

Differential revision: https://reviews.llvm.org/D99054
2021-04-01 17:48:09 -07:00
Alexander Shaposhnikov f1e4e2fb20 [lld][MachO] Refactor handling of subsections
This diff is a preparation for fixing FunStabs (incorrect size calculation).
std::map<uint32_t, InputSection*> (SubsectionMap) is replaced with
a sorted vector + binary search. If .subsections_via_symbols is set
this vector will contain the list of subsections, otherwise,
the offsets will be used for calculating the symbols sizes.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D98837
2021-03-31 16:52:53 -07:00
Jez Ng 9b6dde8af8 [lld-macho] Parallelize UUID hash computation
This reuses the approach (and some code) from LLD-ELF.

It's a decent win when linking chromium_framework on a Mac Pro (3.2 GHz 16-Core Intel Xeon W):

      N           Min           Max        Median           Avg        Stddev
  x  20          4.58          4.83          4.66        4.6685   0.066591844
  +  20          4.42          4.61           4.5         4.505    0.04751731
  Difference at 95.0% confidence
          -0.1635 +/- 0.0370242
          -3.5022% +/- 0.793064%
          (Student's t, pooled s = 0.0578462)

The output binary is 381MB.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99279
2021-03-31 15:48:36 -04:00
Jez Ng 09aed384ba [lld-macho][nfc] Test that -ObjC will import bitcode with category sections
The functionality was originally added in {D95265}, but the test in that
diff only checked if `-ObjC` would cause bitcode containing ObjC class
symbols to be loaded. It neglected to test for bitcode containing
categories but no class symbols.

This diff also changes the lto-archive.ll test to use `-why_load`
instead of inspecting the output binary's symbol table. This is
motivated by the stacked diff {D99105}, which will hide irrelevant
bitcode symbols.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99215
2021-03-31 15:48:36 -04:00
Zequan Wu eabd55b1b2 [lld-link] Enable addrsig table in COFF lto
This allow safe-icf mode to work when linking with LTO.

Differential Revision: https://reviews.llvm.org/D99613
2021-03-30 15:47:53 -07:00
Greg McGary 427d359721 [lld-macho][NFC] Drop unnecessary macho:: namespace prefix on unambiguous references to Symbol
Within `lld/macho/`, only `InputFiles.cpp` and `Symbols.h` require the `macho::` namespace qualifier to disambiguate references to `class Symbol`.

Add braces to outer `for` of a 5-level single-line `if`/`for` nest.

Differential Revision: https://reviews.llvm.org/D99555
2021-03-30 14:58:35 -07:00
Amy Huang 5127da0291 Revert "[COFF] Only consider associated EH sections during ICF"
This change causes an asan error for ODR violation.

This reverts commit 7ce9a3e9a9.
2021-03-29 19:15:35 -07:00
Nico Weber 221388f451 fix comment typo to cycle bots 2021-03-29 14:50:17 -04:00
Nico Weber 742f663705 fix comment typo to cycle bots 2021-03-29 14:35:57 -04:00
Jez Ng a43f588e01 [lld-macho] Implement -segprot
Addresses llvm.org/PR49405.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99389
2021-03-29 14:08:12 -04:00
Jez Ng ae7aa9ed15 [lld-macho] Add time tracing for LTO
The test is similar to the one used for LLD-ELF.

Differential Revision: https://reviews.llvm.org/D99318
2021-03-26 18:14:10 -04:00
Jez Ng 94e369400e [lld-macho] Fix parsing of --time-trace-{granularity,file}
Summary: We needed to use `Joined` instead of `Flag`. This wasn't caught
because the relevant test that was copied from LLD-ELF was still
invoking LLD-ELF instead of LLD-MachO...

Differential Revision: https://reviews.llvm.org/D99313
2021-03-26 18:14:10 -04:00
Jez Ng 45cdceb40c [lld-macho] Support -no_function_starts
Pretty simple code-wise. Also threw in some refactoring:

* Put the functionStartSection under Writer instead of InStruct, since
  it doesn't need to be accessed outside of Writer
* Adjusted the test to put all files under the temp dir instead of at
  the top-level
* Added some CHECK-LABELs to make it clearer where the function starts
  data is

Differential Revision: https://reviews.llvm.org/D99112
2021-03-26 18:14:10 -04:00
Vy Nguyen dee5787d3e Reland [lld-macho][nfc] minor clean up, follow up to D98559
This reverts commit 77b4230ed9.

New change: Fixed tests on windows

     Differential Revision: https://reviews.llvm.org/D99210
2021-03-25 16:46:37 -04:00
Vy Nguyen e2f34cc330 [lld-macho][nfc] Removed unnecessary static_cast
Differential Revision: https://reviews.llvm.org/D99365
2021-03-25 15:07:46 -04:00
Jez Ng 0113cf00b6 [lld-macho] Add support for --threads
Code and test are largely identical to the LLD-ELF equivalents.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D99312
2021-03-25 14:51:31 -04:00
Jez Ng 4bcaafeb0e [lld-macho] Add more TimeTraceScopes
I added just enough to allow us to see a top-level breakdown of time taken. This
is the result of loading the time-trace output into `chrome:://tracing`:

ef5e8234f3/tracing.png

Reviewed By: oontvoo

Differential Revision: https://reviews.llvm.org/D99311
2021-03-25 14:51:31 -04:00
Jez Ng 53fd1ada76 [lld-macho] Fix typo in diagnostic message 2021-03-25 14:51:31 -04:00
Abhina Sreeskantharajan c83cd8feef [NFC] Reordering parameters in getFile and getFileOrSTDIN
In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used.

```
  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFile(const Twine &Filename, bool IsText = false,
          bool RequiresNullTerminator = true, bool IsVolatile = false);

  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFileOrSTDIN(const Twine &Filename, bool IsText = false,
                 bool RequiresNullTerminator = true);

 static ErrorOr<std::unique_ptr<MB>>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
            bool IsText, bool RequiresNullTerminator, bool IsVolatile);

  static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
  getFile(const Twine &Filename, bool IsVolatile = false);
```

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D99182
2021-03-25 09:47:49 -04:00
Martin Storsjö a88556733a [LLD] Fix probing a MSYS based 'tar' in a Windows Container
Don't run the 'tar' tool in a cleared environment with only the
LANG variable set, just set LANG on top of the existing environment.

If the 'tar' tool is an MSYS based tool, running it in a Windows
Container hangs if all environment variables are cleared - in
particular, the USERPROFILE variable needs to be kept intact.

This is the same issue fixed as was fixed in other places in
9de63b2e05, but contrary to running
the actual tests, running with an as-cleared-as-possible environment
here is less important.

Differential Revision: https://reviews.llvm.org/D99304
2021-03-25 09:45:27 +02:00
Yolanda Chen 4f9c61ef72 [lld] add context-sensitive PGO options for COFF.
Add lld CSPGO (Contex-Sensitive PGO) options for COFF target.

Reference the ELF options from https://reviews.llvm.org/D56675

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D98763
2021-03-24 23:40:09 -07:00
Vy Nguyen d988ffc34f [lld-macho][nfc] Fixed test so it output to %t/ rather than current directory.
The a.out broke our build.

Differential Revision: https://reviews.llvm.org/D99271
2021-03-24 16:55:37 -04:00
Konstantin Zhuravlyov 4f28303133 AMDGPU/LLD: Add target id and code object v4 support to linker
Differential Revision: https://reviews.llvm.org/D95811
2021-03-24 13:41:10 -04:00
Konstantin Zhuravlyov f4ace63737 AMDGPU: Add target id and code object v4 support
- Add target id support (https://clang.llvm.org/docs/ClangOffloadBundler.html#target-id)
  - Add code object v4 support (https://llvm.org/docs/AMDGPUUsage.html#elf-code-object)
    - Add kernarg_size to kernel descriptor
    - Change trap handler ABI to no longer move queue pointer into s[0:1]
  - Cleanup ELF definitions
    - Add V2, V3, V4 suffixes to make a clear distinction for code object version
    - Consolidate note names

Differential Revision: https://reviews.llvm.org/D95638
2021-03-24 11:54:05 -04:00
Andy Wingo 9ac5620cb8 [WebAssembly] Rename WasmLimits::Initial to ::Minimum. NFC.
This patch renames the "Initial" member of WasmLimits to the name used
in the spec, "Minimum".

In the core WebAssembly specification, the Limits data type has one
required "min" member and one optional "max" member, indicating the
minimum required size of the corresponding table or memory, and the
maximum size, if any.

Although the WebAssembly spec does instantiate locally-defined tables
and memories with the initial size being equal to the minimum size, it
can't impose such a requirement for imports.  It doesn't make sense to
require an initial size for a memory import, for example.  The compiler
can only sensibly express the minimum and maximum sizes.

See
https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md#naming-of-size-limits
for a related discussion that agrees that the right name of "initial" is
"minimum" when querying the type of a table or memory from JavaScript.
(Of course it still makes sense for JS to speak in terms of an initial
size when it explicitly instantiates memories and tables.)

Differential Revision: https://reviews.llvm.org/D99186
2021-03-24 09:10:11 +01:00
Shoaib Meenai 48d9b2fd8e [lld] Fix test to work with and without a vendor string 2021-03-23 16:16:25 -07:00
Vy Nguyen aa6e4cdd73 [lld-macho] Fixed lld-version expectation in test so it works on Fuchsia.
On Fuchsia, it's called Fuchsia LLD

Differential Revision: https://reviews.llvm.org/D99217
2021-03-23 17:56:23 -04:00
Vy Nguyen 77b4230ed9 Revert "[lld-macho][nfc] minor clean up, follow up to D98559"
This reverts commit 1bc33eb6a3.
tests failed on windows
2021-03-23 17:15:36 -04:00
Vy Nguyen 1bc33eb6a3 [lld-macho][nfc] minor clean up, follow up to D98559
Differential Revision: https://reviews.llvm.org/D99210
2021-03-23 16:13:09 -04:00
Vy Nguyen f499b932bf Revert "Revert "Revert "Revert "Revert "Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)""""""
This reverts commit 4876ba5b2d.

Third-attemp relanding D98559, new change:
  - explicitly cast enum to underlying type to avoid ambiguity (workaround to clang's bug).
2021-03-23 14:51:05 -04:00
Mehdi Amini 4876ba5b2d Revert "Revert "Revert "Revert "Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)"""""
This reverts commit 3c21166a94.
The build is broken (clang-8 host compiler):

lld/MachO/DriverUtils.cpp:271:8: error: use of overloaded operator '<<' is ambiguous (with operand types 'llvm::raw_fd_ostream' and 'lld::macho::DependencyTracker::DepOpCode')
    os << opcode;
    ~~ ^  ~~~~~~
2021-03-23 00:19:12 +00:00
Vy Nguyen 3c21166a94 Revert "Revert "Revert "Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)""""
This reverts commit 9670d2e4af.

Second attemp to reland D98559. New changes:
 - inline functions removed from cpp file.
 - updated tests to use CHECK-DAG instead of CHECK-NEXT
 - fixed ambiguous "<<" operator by switching `char` to uint8_t
2021-03-22 19:34:51 -04:00
Reid Kleckner 7ce9a3e9a9 [COFF] Only consider associated EH sections during ICF
The only known reason why ICF should not merge otherwise identical
sections with differing associated sections has to do with exception
handling tables. It's not clear what ICF should do when there are other
kinds of associated sections. In every other case when this has come up,
debug info and CF guard metadata, we have opted to make ICF ignore the
associated sections.

For comparison, ELF doesn't do anything for comdat groups. Instead,
.eh_frame is parsed to figure out if a section has an LSDA, and if so,
ICF is disabled.

Another issue is that the order of associated sections is not defined.
We have had issues in the past (crbug.com/1144476) where changing the
order of the .xdata/.pdata sections in the object file lead to large ICF
slowdowns.

To address these issues, I decided it would be best to explicitly
consider only .pdata and .xdata sections during ICF. This makes it easy
to ignore the object file order, and I think it makes the intention of
the code clearer.

I've also made the children() accessor return an empty list for
associated sections. This mostly only affects ICF and GC. This was the
behavior before I made this a linked list, so the behavior change should
be good. This had positive effects on chrome.dll: more .xdata sections
were merged that previously could not be merged because they were
associated with distinct .pdata sections.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D98993
2021-03-22 15:36:26 -07:00
Reid Kleckner e5646e4570 [PDB] Add missing test for b552adf8b3 2021-03-22 14:56:36 -07:00
Vy Nguyen 9670d2e4af Revert "Revert "Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)"""
This reverts commit 5ad2c225f3.

bots still  unhappy - revertting again
2021-03-22 14:54:01 -04:00
Vy Nguyen 5ad2c225f3 Revert "Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)""
This reverts commit 2554b95db5.

Relanding [lld-macho] Implement -dependency_info (D98559) with changes:
 - inline functions removed from cpp file.
 - updated tests to not check libSystem.tbd with other input files (because of possible indeterministic ordering)
2021-03-22 14:41:57 -04:00
Stefan Pintilie f21704e080 [LLD][PowerPC] Fix bug in PC-Relative initial exec
There is a bug when initial exec is relaxed to local exec.
In the following situation:

InitExec.c
```
extern __thread unsigned TGlobal;
unsigned getConst(unsigned*);
unsigned addVal(unsigned, unsigned*);

unsigned GetAddrT() {
  return addVal(getConst(&TGlobal), &TGlobal);
}
```

Def.c
```
__thread unsigned TGlobal;

unsigned getConst(unsigned* A) {
  return *A + 3;
}

unsigned addVal(unsigned A, unsigned* B) {
  return A + *B;
}
```

The problem is in InitExec.c but Def.c is required if you want to link the example and see the problem.
To compile everything:
```
clang -O3 -mcpu=pwr10 -c InitExec.c
clang -O3 -mcpu=pwr10 -c Def.c
ld.lld InitExec.o Def.o -o IeToLe
```

If you objdump the problem object file:
```
$ llvm-objdump -dr --mcpu=pwr10 InitExec.o
```
you will get the following assembly:
```
0000000000000000 <GetAddrT>:
       0: a6 02 08 7c  	mflr 0
       4: f0 ff c1 fb  	std 30, -16(1)
       8: 10 00 01 f8  	std 0, 16(1)
       c: d1 ff 21 f8  	stdu 1, -48(1)
      10: 00 00 10 04 00 00 60 e4      	pld 3, 0(0), 1
		0000000000000010:  R_PPC64_GOT_TPREL_PCREL34	TGlobal
      18: 14 6a c3 7f  	add 30, 3, 13
		0000000000000019:  R_PPC64_TLS	TGlobal
      1c: 78 f3 c3 7f  	mr	3, 30
      20: 01 00 00 48  	bl 0x20
		0000000000000020:  R_PPC64_REL24_NOTOC	getConst
      24: 78 f3 c4 7f  	mr	4, 30
      28: 30 00 21 38  	addi 1, 1, 48
      2c: 10 00 01 e8  	ld 0, 16(1)
      30: f0 ff c1 eb  	ld 30, -16(1)
      34: a6 03 08 7c  	mtlr 0
      38: 00 00 00 48  	b 0x38
		0000000000000038:  R_PPC64_REL24_NOTOC	addVal
```
The lines of interest are:
```
      10: 00 00 10 04 00 00 60 e4      	pld 3, 0(0), 1
		0000000000000010:  R_PPC64_GOT_TPREL_PCREL34	TGlobal
      18: 14 6a c3 7f  	add 30, 3, 13
		0000000000000019:  R_PPC64_TLS	TGlobal
      1c: 78 f3 c3 7f  	mr	3, 30
```
Which once linked gets turned into:
```
10010210: ff ff 03 06 00 90 6d 38      	paddi 3, 13, -28672, 0
10010218: 00 00 00 60  	nop
1001021c: 78 f3 c3 7f  	mr	3, 30
```
The problem is that register 30 is never set after the optimization.

Therefore it is not correct to relax the above instructions by replacing
the add instruction with a nop.
Instead the add instruction should be replaced with a copy (mr) instruction.
If the add uses the same resgiter as input and as ouput then it is safe to
continue to replace the add with a nop.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D95262
2021-03-22 13:15:44 -05:00
Yang Fan 0db28c0f3b
[ELF][docs] Add line breaks 2021-03-22 16:08:47 +08:00
Nico Weber 2554b95db5 Revert "[lld-macho] Implement -dependency_info (partially - more opcodes needed)"
This reverts commit c53a1322f3.
Test only passes depending on build dir having a lexicographically later name
than the source dir, and doesn't link on mac/win. See
https://reviews.llvm.org/D98559#2640265 onward.
2021-03-21 16:35:38 -04:00
Vy Nguyen c53a1322f3 [lld-macho] Implement -dependency_info (partially - more opcodes needed)
Bug: https://bugs.llvm.org/show_bug.cgi?id=49278
The flag is not well documented, so this implementation is based on observed behaviour.

When specified, `-dependency_info <path>` produced a text file containing information pertaining to the current linkage, such as input files, output file, linker version, etc.

This file's layout is also not documented, but it seems to be a series of null ('\0') terminated strings in the form `<op code><path>`

`<op code>` could be:
   `0x00` : linker version
   `0x10` : input
   `0x11` : files not found(??)
   `0x40` : output

`<path>` : is the file path, except for the linker-version case.

(??) This part is a bit unclear. I think it means all the files the linker attempted to look at, but could not find.

Differential Revision: https://reviews.llvm.org/D98559
2021-03-21 14:35:46 -04:00
Jez Ng 8757616de3 [lld-macho][nfc] Format Options.td
Summary: A good chunk of it was mis-indented. Fixed by using the
formatting settings from llvm/utils/vim.
2021-03-21 09:33:04 -04:00
Jez Ng 47fdaa32f9 [lld-macho] Minor touch-up to objc.s 2021-03-20 14:42:16 -04:00
Vy Nguyen 6c1ae8f2dc [lld-macho][nfc] Fixed typo in comment
Missed this one from https://reviews.llvm.org/D97007?id=331759#inline-930034

Differential Revision: https://reviews.llvm.org/D98973
2021-03-19 14:19:36 -04:00
Vy Nguyen 66f340051a [lld-macho] Define __mh_*_header synthetic symbols.
Bug: https://bugs.llvm.org/show_bug.cgi?id=49290

    Differential Revision: https://reviews.llvm.org/D97007
2021-03-19 14:14:40 -04:00