1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
Commit Graph

12090 Commits

Author SHA1 Message Date
Georgii Rymar
c069c24df3 [llvm-readelf] - Simplify the implementation of getSectionTypeString() helper. NFCI.
It is used for printing section headers in the GNU style
and the implementation can be simplified.

Differential revision: https://reviews.llvm.org/D84330
2020-07-23 13:04:42 +03:00
Roman Lebedev
67198bc6db [Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target
Summary:
If there was a single target to begin with, because a single target
can only occupy a single chunk, we couldn't increase granularity.
and would immediately give up.

Likewise, if we had multiple targets, if by the end we'd end up with
a single target, we wouldn't finish reducing it, it would always
end up being "interesting"

Reviewers: dblaikie, nickdesaulniers, diegotf

Reviewed By: dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84318
2020-07-23 10:51:46 +03:00
Rong Xu
005085c634 [PGO] Supporting code for always instrumenting entry block
This patch includes the supporting code that enables always
instrumenting the function entry block by default.

This patch will NOT the default behavior.

It adds a variant bit in the profile version, adds new directives in
text profile format, and changes llvm-profdata tool accordingly.

This patch is a split of D83024 (https://reviews.llvm.org/D83024)
Many test changes from D83024 are also included.

Differential Revision: https://reviews.llvm.org/D84261
2020-07-22 15:01:53 -07:00
Georgii Rymar
52edb26a18 [llvm-readobj] - Don't get the name of the symbol table in ELFDumper<ELFT>::printSymbolsHelper.
It was requested in D84173 thread to not do it, because otherwise we extract and
check the name of the symbol table in LLVM style, but do not use it and
might report a warning which perhaps might be confusing.

Differential revision: https://reviews.llvm.org/D84231
2020-07-22 17:28:20 +03:00
Georgii Rymar
f31c1bd833 [llvm-readelf] - Introduce describe() helper functions.
These functions can be used to generate strings like
"SHT_?? section with index ?" to describe sections in error/warning messages,
what helps to simplify and generalize them.

Also this allows to isolate the following common code pattern:
`&Sec - &cantFail(Obj->sections()).front();`

Differential revision: https://reviews.llvm.org/D84240
2020-07-22 14:03:17 +03:00
Georgii Rymar
b979a82ecf [llvm-readelf/readobj] - Fix the behavior when a sections is included in two groups at the same time.
The current behavior was introduced by me in D37567 and it is a bit strange. It prints the
"Error: ...." message to the errs() manually and stops dumping the group section which has this error.
This behavior is consistent with GNU though, but it is very inconsistent with what the regular llvm-readelf
code usually does/prints, so I suggest to change the implementation:

1) Instead of printing "Error: ...." to errs() - just report a warning.
2) Try to continue dumping the section.
3) Merge broken-group.test to group.text.

This is what this patch does.

Differential revision: https://reviews.llvm.org/D84170
2020-07-22 13:29:54 +03:00
Georgii Rymar
c7641fc229 [llvm-readobj/readelf] - Don't fail dumping when unable to read the name of the SHT_DYNSYM section.
We have an issue currently: we are trying to read the name of the SHT_DYNSYM section
very early and using `unwrapOrError` call for that.

The name is needed only for the GNU output. Because of the current logic, the tool
fails to dump the whole object when something is wrong with the name of the .dynsym section.

This patch delays reading the name and also allows it to be broken.

Differential revision: https://reviews.llvm.org/D84173
2020-07-22 13:11:46 +03:00
Roman Lebedev
eb0d395cfb [NFC][Reduce] Group llvm-reduce options into a group, uncluttering --help 2020-07-22 10:00:31 +03:00
Sameer Arora
10d39a6183 [llvm-libtool-darwin] Allow flattening archives
Add support for flattening archives while creating static libraries.
Hence, can now pass archives as input in addition to Mach-O binaries.
Furthermore, archives themselves must only conatain Mach-O binaries. As
per cctools' libtool's behavior, llvm-libtool-darwin does not flatten
archives recursively.

Reviewed by alexshap, smeenai, jhenderson

Differential Revision: https://reviews.llvm.org/D83520
2020-07-21 13:53:15 -07:00
Sameer Arora
6e98d8a897 [llvm-libtool-darwin] Add support for -static option
Add support for creating static libraries when the input includes only
Mach-O binaries (and not libraries/archives themselves).

Reviewed by alexshap, Ktwu, smeenai, jhenderson, MaskRay, mtrent

Differential Revision: https://reviews.llvm.org/D83002
2020-07-21 13:08:49 -07:00
Arthur Eubanks
c136b2bbc8 [NewPM] Support optnone under new pass manager
OptNoneInstrumentation is part of StandardInstrumentations. It skips
functions (or loops) that are marked optnone.

The feature of skipping optional passes for optnone functions under NPM
is gated on a -enable-npm-optnone flag. Currently it is by default
false. That is because we still need to mark all required passes to be
required. Otherwise optnone functions will start having incorrect
semantics.  After that is done in following changes, we can remove the
flag and always enable this.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D83519
2020-07-21 09:53:43 -07:00
Fangrui Song
670f47ee88 [llvm-readobj] Construct relocation-aware DWARFDataExtractor to decode .eh_frame addresses correctly
In an object file, a "PC Begin" field in a FDE is usually relocated by a
PC-relative relocation. Use a relocation-aware DWARFDataExtractor overload (with
DWARFContext and a reference to its internal .eh_frame representation) to decode
addresses correctly. In an object file, most sections have addresses of zero. So
the displayed addresses are almost always offsets relative to the start of the
associated text section.

DWARFContext::create handles .eh_frame and .rela.eh_frame by itself, so if there
are more than one .eh_frame (technically possible, but almost always erronerous
in practice), this will only handle the first one.  Supporting multiple
.eh_frame is beyond the scope of this patch.

Reviewed By: grimar, jhenderson

Differential Revision: https://reviews.llvm.org/D84106
2020-07-21 08:33:19 -07:00
Djordje Todorovic
bd9b7ebd66 [NFC][Debugify] Rename OptCustomPassManager into DebugifyCustomPassManager
In addition, move the definition of the class into the Debugify.h,
so we can use it from different levels.

The motivation for this is D82547.

Differential Revision: https://reviews.llvm.org/D83391
2020-07-21 12:16:07 +02:00
Roman Lebedev
0885e066d4 [Reduce] Argument reduction: don't try to drop terminator instructions
Newly-added test previously crashed.

While it is up for debate whether or not instruction reduction
should be indiscriminate in instruction dropping (there you can
just ensure that the test case is still -verify'ies), here
if we drop terminator, CloneFunctionInto() will immediately crash.

So let's not do that :)
2020-07-21 00:06:03 +03:00
Fangrui Song
5a1c9a0071 [llvm-readobj] clang-format DwarfCFIEHPrinter.h, NFC
Pre-commit header ordering changes (and other minor clean-ups) before landing D84106.
2020-07-20 10:25:16 -07:00
Fangrui Song
6f16bde0e0 [LLVMgold.so] -plugin-opt=save-temps: save combined module to .lto.o instead of .o
This matches LLD and fixes https://sourceware.org/bugzilla/show_bug.cgi?id=26262#c1

.o is a bad choice for save-temps output because it is easy to override the bitcode file (*.o)

```
 # Use bfd for the example, -fuse-ld=gold is similar.
clang -flto -c a.c  # generate bitcode file a.o
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps  # override a.o

 # The user repeats the command but get surprised, because a.o is now a combined module.
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps
```

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D84132
2020-07-20 10:02:56 -07:00
Elvina Yakubova
9d37b40f76 [llvm-readobj] Print error when executed with no input files
This patch changes llvm-readelf (and llvm-readobj for consistency)
behavior to print an error when executed with no input files.

Reading from stdin can be achieved via a '-' for the input
object.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46400

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

Reviewed by: jhenderson, MaskRay, sbc, jyknight
2020-07-20 10:39:05 +01:00
Georgii Rymar
e4864223fe [llvm-readobj] - Refactor how the code dumps relocations.
There is a strange "feature" of the code: it handles all relocations as `Elf_Rela`.
For handling `Elf_Rel` it converts them to `Elf_Rela` and passes `bool IsRela` to
specify the real type everywhere.

A related issue is that the
`decode_relrs` helper in lib/Object has to return `Expected<std::vector<Elf_Rela>>`
because of that, though it could return a vector of `Elf_Rel`.

I think we should just start using templates for relocation types, it makes the code
cleaner and shorter. This patch does it.

Differential revision: https://reviews.llvm.org/D83871
2020-07-20 12:05:05 +03:00
Georgii Rymar
8e67d52a27 [llvm-readelf/readobj] - Refine the error reporting in printMipsABIFlags() methods.
It fixes/improves the following:
1) Some code was duplicated.
2) A "The .MIPS.abiflags section has a wrong size" error was not reported as a warning,
   but was printed to stdout for the LLVM style. Also, it was reported as an error for the GNU style.
   This patch changes the behavior to be consistent and to report warnings.
3) `unwrapOrError()` was used before, now a warning is reported instead.

Differential revision: https://reviews.llvm.org/D84033
2020-07-20 11:30:17 +03:00
Alex Richardson
f2c854cb7c [llvm-reduce] Fix incorrect indices in argument reduction pass
The function extractArgumentsFromModule() was passing a one-based index to,
but replaceFunctionCalls() was expecting a zero-based argument index. This
resulted in assertion errors when reducing function call arguments with
different types. Additionally, the

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D84099
2020-07-19 18:06:47 +01:00
Logan Smith
91df560a5c [llvm][NFC] Add missing 'override' 2020-07-19 09:57:14 -07:00
Fangrui Song
adac7ac5fb [llvm-cov gcov] Don't require NUL terminator when reading files
.gcno, .gcda and source files can be modified while we are reading them. If the
concurrent modification of a file being read nullifies the NUL terminator
assumption, llvm-cov can trip over an assertion failure in MemoryBuffer::init.
This is not so rare - the source files can be in an editor and .gcda can be
written by an running process (if the process forks, when .gcda gets written is
probably more unpredictable).

There is no accompanying test because an assertion failure requires data
races with some involved setting.
2020-07-19 00:31:52 -07:00
Arthur Eubanks
92a77f4b5e [NewPM][ASan] Make ASan tests work under NPM
Under NPM, the asan-globals-md analysis is required but cannot be run
within the asan function pass due to module analyses not being able to
run from a function pass. So this pins all tests using "-asan" to the
legacy PM and adds a corresponding RUN line with
-passes='require<asan-globals-md>,function(asan)'.

Now all tests in Instrumentation/AddressSanitizer pass when
-enable-new-pm is by default on.

Tests were automatically converted using the following python script and
failures were manually fixed up.

import sys
for i in sys.argv:
    with open(i, 'r') as f:
        s = f.read()
    with open(i, 'w') as f:
        for l in s.splitlines():
            if "RUN:" in l and ' -asan -asan-module ' in l and '\\' not in l:
                f.write(l.replace(' -asan -asan-module ', ' -asan -asan-module -enable-new-pm=0 '))
                f.write('\n')
                f.write(l.replace(' -asan -asan-module ', " -passes='require<asan-globals-md>,function(asan),module(asan-module)' "))
                f.write('\n')
            elif "RUN:" in l and ' -asan ' in l and '\\' not in l:
                f.write(l.replace(' -asan ', ' -asan -enable-new-pm=0 '))
                f.write('\n')
                f.write(l.replace(' -asan ', " -passes='require<asan-globals-md>,function(asan)' "))
                f.write('\n')
            else:
                f.write(l)
                f.write('\n')

See https://bugs.llvm.org/show_bug.cgi?id=46611.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D83921
2020-07-17 18:01:25 -07:00
Lang Hames
29e51c11e5 [llvm-jitlink] Add suppport for testing GOT entries and stubs for ELF.
This enables regression testing of GOT and stub handling with
llvm-jitlink.
2020-07-17 17:55:30 -07:00
Logan Smith
435cea1283 [llvm][NFC] Add missing 'override's 2020-07-17 17:35:59 -07:00
Sameer Arora
4336e89619 Introducing llvm-libtool-darwin
This diff starts the implementation of llvm-libtool-darwin
(an llvm based replacement of cctool's libtool).
Libtool is used for creating static and dynamic libraries
from a bunch of object files given as input.

Reviewed by alexshap, smeenai, jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D82923
2020-07-17 08:07:02 -07:00
Clement Courbet
17ad6e2f24 Revert "[llvm-exegesis] Add benchmark latency option on X86 that uses LBR for more precise measurements."
From @erichkeane:
```
This patch doesn't seem to build for me:
/iusers/ekeane1/workspaces/llvm-project/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp: In function ‘llvm::Error llvm::exegesis::parseDataBuffer(const char*, size_t, const void*, const void*, llvm::SmallVector<long int, 4>*)’:
/iusers/ekeane1/workspaces/llvm-project/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp:99:37: error: ‘struct perf_branch_entry’ has no member named ‘cycles’

CycleArray->push_back(Entry.cycles);
I'm on RHEL7, so I have kernel 3.10, so it doesn't have 'cycles'.

According ot this: https://elixir.bootlin.com/linux/v4.3/source/include/uapi/linux/perf_event.h#L963 kernel 4.3 is the first time that 'cycles' appeared in this structure.
```
2020-07-17 16:55:17 +02:00
Vy Nguyen
86e9087897 [llvm-exegesis] Add benchmark latency option on X86 that uses LBR for more precise measurements.
Starting with Skylake, the LBR contains the precise number of cycles between the two
    consecutive branches.
    Making use of this will hopefully make the measurements more precise than the
    existing methods of using RDTSC.

            Differential Revision: https://reviews.llvm.org/D77422
2020-07-16 12:12:46 -04:00
Georgii Rymar
99edb55f34 [yaml2obj] - Rename FileHeader::SH* fields.
In D83482 we agreed to name e_* fields that are used for overriding
values (like e_phoff) as EPh* (e.g. EPhOff).

Currently we have a set of e_sh* fields that are named inconsistently
with this rule. This patch renames all of them.

Differential revision: https://reviews.llvm.org/D83766
2020-07-15 12:47:31 +03:00
Jan Sjodin
1e6d1b7612 llvm-link: Add support for archive files as inputs
This patch adds support for archive files as inputs to llvm-link. One
of the use-cases is for OpenMP, where device specific libraries need
to be extracted from libraries containing bundled object files. The
clang-offload-bundler will support extracting these archives, which
will be passed into llvm-link, see https://reviews.llvm.org/D80816.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D81109
2020-07-14 15:30:59 -04:00
Georgii Rymar
14dff304c5 [test/Object][llvm-objdump] - llvm-objdump: don't abort() when the e_phoff field is invalid and refine testing.
llvm-objdump currently calls report_fatal_error() when the e_phoff field is invalid.

This is tested by elf-invalid-phdr.test which has the following issues:
1) It uses a precompiled object.
2) it could be a part of invalid.test.
3) It tests the Object lib, but we have no separate test for llvm-objdump.

This patch addresses issues mentioned.

Differential revision: https://reviews.llvm.org/D83559
2020-07-14 14:45:18 +03:00
Georgii Rymar
3e8c0f5b9f [llvm-readobj] - Stop using unwrapOrError() for all program_headers() calls.
program_headers() returns the list of program headers. This change allows
to continue attempt of dumping when something is wrong with program headers.

Differential revision: https://reviews.llvm.org/D83554
2020-07-14 14:16:57 +03:00
Georgii Rymar
90742a774c [yaml2obj] - Add a syntax to override e_phoff, e_phentsize and e_phnum fields.
This adds `EPhOff`, `EPhEntSize` and `EPhNum` keys.
Will be useful for creating broken objects for testing llvm-readelf.

Differential revision: https://reviews.llvm.org/D83482
2020-07-14 13:16:19 +03:00
Arthur Eubanks
084b730605 [NewPM][opt] Translate -foo-analysis to require<foo-analysis>
Fixes 53 check-llvm tests under NPM.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D83633
2020-07-13 11:24:59 -07:00
Georgii Rymar
e9920e279f [llvm-readobj] - Add a generic test for --dyn-relocations and fix an issue.
We have an issue currently: --dyn-relocations always prints the following
relocation header when dumping `DynPLTRelRegion`:

"Offset  Info  Type Symbol's Value  Symbol's Name + Addend"

I.e. even for an empty object, --dyn-relocations still prints this.
It is a easy to fix bug, but we have no dedicated test case for this option.
(we have a dynamic-reloc-no-section-headers.test, which has a slightly different purpose).

This patch adds a test and fixes the behavior.

Differential revision: https://reviews.llvm.org/D83387
2020-07-13 14:22:03 +03:00
Wei Mi
ac5dfca575 [NFC] Extract the code to write instr profile into function writeInstrProfile
So that the function writeInstrProfile can be used in other places.

Differential Revision: https://reviews.llvm.org/D83521
2020-07-09 16:30:28 -07:00
Roman Lebedev
892d28a558 [llvm-reduce] Reducing attributes
Summary:
This handles all three places where attributes could currently be - `GlobalVariable`, `Function` and `CallBase`.
For last two, it correctly handles all three possible attribute locations (return value, arguments and function itself)

There was a previous attempt at it D73853,
which was committed in rGfc62b36a000681c01e993242b583c5ec4ab48a3c,
but then reverted all the way back in rGb12176d2aafa0ccb2585aa218fc3b454ba84f2a9
due to some (osx?) test failures.

Reviewers: nickdesaulniers, dblaikie, diegotf, george.burgess.iv, jdoerfert, Tyker, arsenm

Reviewed By: nickdesaulniers

Subscribers: wdng, MaskRay, arsenm, llvm-commits, mgorny

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83351
2020-07-09 23:10:43 +03:00
Roman Lebedev
90826c519d [NFC][llvm-reduce] Purify for_each usage in Operand Bundles into range-based for loop
Summary:
As per lengthy/heated disscussion in D83351,
and CodingStandards D83431.

Reviewers: dblaikie, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83434
2020-07-09 23:10:43 +03:00
Roman Lebedev
1036a9e7d6 [NFCI][llvm-reduce] OperandBundleCounter: drop pointless constructor
Reviewers: nickdesaulniers, dblaikie

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83435
2020-07-09 23:10:42 +03:00
Simon Pilgrim
25bfa43832 Fix MSVC "not all control paths return a value" warning. NFC. 2020-07-09 15:01:13 +01:00
Georgii Rymar
19e136db64 [llvm-readelf] - Stop using 'unwrapOrError()' in 'ELFDumper<ELFT>::getSymbolVersion'.
This allows to propagate an error and report a warning properly.

Differential revision: https://reviews.llvm.org/D83393
2020-07-09 13:43:52 +03:00
Oliver Stannard
e53ceb3dc0 [llvm-objdump] Display locations of variables alongside disassembly
This adds the --debug-vars option to llvm-objdump, which prints
locations (registers/memory) of source-level variables alongside the
disassembly based on DWARF info. A vertical line is printed for each
live-range, with a label at the top giving the variable name and
location, and the position and length of the line indicating the program
counter range in which it is valid.

Differential revision: https://reviews.llvm.org/D70720
2020-07-09 09:58:00 +01:00
Arthur Eubanks
3d264d72b7 [opt] Remove obsolete --quiet option
git blame shows these were last touched in 2004?
 Obsoleted in r13844.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D83409
2020-07-08 13:21:20 -07:00
Arthur Eubanks
e8d13f6c1b [NewPM][opt] Translate "-O#" to NPM's "default<O#>"
Fixes 52 check-llvm tests under NPM.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D83367
2020-07-08 09:01:20 -07:00
Arthur Eubanks
bcce08feb7 [NewPM][opt] Share -disable-loop-unrolling between pass managers
There's no reason to introduce a new option for the NPM.
The various PGO options are shared in this manner.

Reviewed By: echristo

Differential Revision: https://reviews.llvm.org/D83368
2020-07-08 08:50:56 -07:00
Roman Lebedev
986cd9219d [NFCI][llvm-reduce] Cleanup Delta passes to use Oracle abstraction
Summary:
I think, this results in much more understandable/readable flow.
At least the original logic was perhaps the most hard thing for me to grasp when taking an initial look on the delta passes.

Reviewers: nickdesaulniers, dblaikie, diegotf, george.burgess.iv

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83287
2020-07-08 12:26:00 +03:00
Georgii Rymar
54223457e2 [llvm-readobj] - Refine error reporting in MipsGOTParser<ELFT> helper.
This is a follow-up for D83225. This does the following:
1) Adds missing tests for existent errors.
2) Stops using `unwrapOrError` to propagate errors to caller.
   (I am trying to get rid of all `unwrapOrErr` calls in the llvm-readelf code).
3) Improves error messages reported slightly.

Differential revision: https://reviews.llvm.org/D83314
2020-07-08 12:05:52 +03:00
Georgii Rymar
089f3ae98c [llvm-readobj] - Refactor the MipsGOTParser<ELFT> to stop using report_fatal_error().
`MipsGOTParser` is a helper class that is used to dump MIPS GOT and PLT.
There is a problem with it: it might call report_fatal_error() on invalid input.
When this happens, the tool reports a crash:

```
# command stderr:
LLVM ERROR: Cannot find PLTGOT dynamic table tag.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backt
race.
Stack dump:
...
```

Such error were not tested. In this patch I've refactored `MipsGOTParser`:

I've splitted handling of GOT and PLT to separate methods. This allows to propagate
any possible errors to caller and should allow to dump the PLT when something is wrong
with the GOT and vise versa in the future.

I've added tests for each `report_fatal_error()`
and now calling the `reportError` instead. In the future we might want to switch to
reporting warnings, but it requres the additional testing and should
be performed independently.

I've kept `unwrapOrError` calls untouched for now as I'd like to focus on eliminating
`report_fatal_error` calls in this patch only.

Differential revision: https://reviews.llvm.org/D83225
2020-07-07 16:43:38 +03:00
Georgii Rymar
d4b928b169 [llvm-readobj] - Don't abort when dumping dynamic relocations when an object has both REL and RELA.
Currently, llvm-readobj calls `report_fatal_error` when an object has
both REL and RELA dynamic relocations.

llvm-readelf is able to handle this case properly. This patch adds such a test case
and adjusts the llvm-readobj code to follow (and be consistent with its own RELR and PLTREL cases).

Differential revision: https://reviews.llvm.org/D83232
2020-07-07 16:14:51 +03:00
Georgii Rymar
76117cb7dd [llvm-readobj] - Refine the error reporting in LLVMStyle<ELFT>::printELFLinkerOptions.
It is possible to:
1) Avoid using the `unwrapOrError` calls and hence allow to continue dumping even when
   something is not OK with one of SHT_LLVM_LINKER_OPTIONS sections.
2) replace `reportWarning` with `reportUniqueWarning` calls. In this method it is no-op,
   because it is not possible to have a duplicated warnings anyways, but since we probably
   want to switch to `reportUniqueWarning` globally, this is a good thing to do.

This patch addresses both these points.

Differential revision: https://reviews.llvm.org/D83131
2020-07-07 14:04:17 +03:00
Georgii Rymar
120dc4c2d4 [llvm-readobj] - Split the printHashSymbols. NFCI.
This introduces `printHashTableSymbols` and
`printGNUHashTableSymbols` to split the `printHashSymbols`.

It makes the code more readable and consistent.

Differential revision: https://reviews.llvm.org/D83040
2020-07-07 14:01:34 +03:00
Georgii Rymar
2b61b9d440 [llvm-readobj] - Refactor ELFDumper<ELFT>::getStaticSymbolName.
This is a followup for D83129.
It is possible to make `getStaticSymbolName` report warnings inside
and return the "<?>" on a error. This allows to encapsulate errors handling
and slightly simplifies the logic in callers code.

Differential revision: https://reviews.llvm.org/D83208
2020-07-07 13:33:47 +03:00
Georgii Rymar
5a53f6b304 [llvm-readobj] - Allow dumping partially corrupted SHT_LLVM_CALL_GRAPH_PROFILE sections.
The code we have currently reports an error if something is not right with the
profile section. Instead we can report a warning and continue dumping when it is possible.
This patch does it.

Differential revision: https://reviews.llvm.org/D83129
2020-07-07 13:30:12 +03:00
Georgii Rymar
1e4f015d35 [llvm-readobj] - Fix a crash scenario in GNUStyle<ELFT>::printHashSymbols().
We might crash when the dynamic symbols table is empty (or not found)
and --hash-symbols is requested. Both .hash and .gnu.hash logic is affected.

The patch fixes this issue.

Differential revision: https://reviews.llvm.org/D83037
2020-07-07 11:59:00 +03:00
Sameer Arora
9aaa6b386c [llvm-install-name-tool] Merge install-name options
This diff merges all options for llvm-install-name-tool under a single
function processLoadCommands. Also adds another test case for -add_rpath
option.

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

Differential Revision: https://reviews.llvm.org/D82812
2020-07-06 20:32:32 -07:00
Eric Christopher
38ba3bf0b6 Temporarily Revert "[llvm-install-name-tool] Merge install-name options" as it breaks the objcopy build.
This reverts commit c143900a0851b2c7b7d52e4825c7f073b3474cf6.
2020-07-06 15:40:14 -07:00
Roman Lebedev
abd4ea9318 [NFCI][llvm-reduce] ReduceOperandBundles: actually put Module forward-declaration back into llvm namespace 2020-07-07 01:32:26 +03:00
Roman Lebedev
40f6d0064d [llvm-reduce] Reducing call operand bundles
Summary:
This would have been marginally useful to me during/for rG7ea46aee3670981827c04df89b2c3a1cbdc7561b.

With ongoing migration to representing assumes via operand bundles on the assume, this will be gradually more useful.

Reviewers: nickdesaulniers, diegotf, dblaikie, george.burgess.iv, jdoerfert, Tyker

Reviewed By: nickdesaulniers

Subscribers: hiraditya, mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83177
2020-07-07 01:16:37 +03:00
Sameer Arora
c3954a3cf0 [llvm-install-name-tool] Merge install-name options
This diff merges all options for llvm-install-name-tool under a single
function processLoadCommands. Also adds another test case for -add_rpath
option.

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

Differential Revision: https://reviews.llvm.org/D82812
2020-07-06 15:15:20 -07:00
Arlo Siemsen
07457fd3ce Add option LLVM_NM to allow specifying the location of the llvm-nm tool
The new option works like the existing LLVM_TABLEGEN, and
LLVM_CONFIG_PATH options.  Instead of building llvm-nm, the build uses
the executable defined by LLVM_NM.

This is useful for cross-compilation scenarios where the host cannot run
the cross-compiled tool, and recursing into another cmake build is not
an option (due to required DEFINE's, for example).

Reviewed By: smeenai

Differential Revision: https://reviews.llvm.org/D83022
2020-07-06 13:27:56 -07:00
Georgy Komarov
564d25cbd9 [llvm-objcopy] Fix crash when removing symbol table at same time as adding a symbol
This patch resolves crash that occurs when user wanted to remove all
symbols and add a brand new one using:

```
llvm-objcopy -R .symtab --add-symbol foo=1234 in.o out.o
```

Before these changes the symbol table internally being null when adding
new symbols. For now we will regenerate symtab in this case.

This fixes: https://bugs.llvm.org/show_bug.cgi?id=43930

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82935
2020-07-05 05:14:00 +03:00
Roman Lebedev
a24529a504 [llvm-reduce] extractGVsFromModule(): don't crash when deleting instr twice
As it can be seen in newly-added (previously-crashing) test-case,
there can be a situation where multiple GV's are used in instr,
and we would schedule the same instruction to be deleted several times,
crashing when trying to delete it the second time.

We could either store WeakVH (done here), or use something set-like.
I think using WeakVH is prevalent in these cases elsewhere.
2020-07-05 01:01:46 +03:00
Roman Lebedev
f794b74374 [llvm-reduce] extractArgumentsFromModule(): don't crash when deleting instr twice
As it can be seen in newly-added (previously-crashing) test-case,
there can be a situation where multiple arguments are used in instr,
and we would schedule the same instruction to be deleted several times,
crashing when trying to delete it the second time.

We could either store WeakVH (done here), or use something set-like.
I think using WeakVH is prevalent in these cases elsewhere.
2020-07-05 00:52:42 +03:00
Georgii Rymar
9740166fc0 [llvm-readobj] - Use cantFail() for all Obj->sections() calls. NFCI.
`ELFDumper<ELFT>::ELFDumper` calls `Obj->sections()` in its constructor:
https://github.com/llvm/llvm-project/blob/master/llvm/tools/llvm-readobj/ELFDumper.cpp#L2046

this means that all subsequent calls can't fail and can be
wrapped into `cantFail` in instead of `unwrapOrError` for simplicity.

Actually we already do it in a few places. In this patch I've fixed all
other places I've found.

Differential revision: https://reviews.llvm.org/D83126
2020-07-03 16:25:20 +03:00
Xing GUO
120aef86f5 [DWARFYAML][debug_gnu_*] Add the missing context IsGNUStyle. NFC.
This patch helps add the missing context `IsGNUStyle`. Before this patch, yaml2obj cannot parse the YAML description of 'debug_gnu_pubnames' and 'debug_gnu_pubtypes' correctly due to the missing context.

In other words, if we have

```
DWARF:
  debug_gnu_pubtypes:
    Length:
      TotalLength: 0x1234
    Version:    2
    UnitOffset: 0x1234
    UnitSize:   0x4321
    Entries:
      - DieOffset:  0x12345678
        Name:       abc
        Descriptor: 0x00      ## Descriptor can never be mapped into Entry.Descriptor
```

yaml2obj will complain that "error: unknown key 'Descriptor'".

This patch helps resolve this problem.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82435
2020-07-03 18:12:58 +08:00
Georgii Rymar
1de44904a6 [llvm-readelf] - Do not report a misleading warning when there is no string table.
This is a follow-up for D82955, which allows to continue dumping when a symbol table is broken.
When we are unable to get the string table and trying to print symbols,
the existent tool logic together with D82955 reports an error:

"st_name (0x??) is past the end of the string table of size 0x??"

Though, when there is no string table, this message becomes misleading and excessive.
It is easy to fix it though and that is what this patch does.

Differential revision: https://reviews.llvm.org/D83042
2020-07-03 11:56:37 +03:00
Georgii Rymar
73e2acf290 [llvm-readelf] - Do not error out when dumping symbols.
When the --symbols option/--dyn-symbols is given we might report an
error and exit when something goes not right. E.g. when the SHT_SYMTAB
section is broken. Though we could report a warning and try to continue
dumping instead in many cases.

This patch removes `unwrapOrErr` calls from the code involved in the
flow described.

Differential revision: https://reviews.llvm.org/D82955
2020-07-03 11:55:35 +03:00
Sameer Arora
d13ebe32f6 Fix typo and check commit access. 2020-07-02 14:49:47 -07:00
Xiang1 Zhang
2a61d4a241 [X86-64] Support Intel AMX instructions
Summary:
INTEL ADVANCED MATRIX EXTENSIONS (AMX).
AMX is a new programming paradigm, it has a set of 2-dimensional registers
(TILES) representing sub-arrays from a larger 2-dimensional memory image and
operate on TILES.

Spec can be found in Chapter 3 here https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Reviewers: LuoYuanke, annita.zhang, pengfei, RKSimon, xiangzhangllvm

Reviewed By: xiangzhangllvm

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82705
2020-07-02 08:57:04 +08:00
gbreynoo
b02a489508 [llvm-size] Output REL, RELA and STRTAB sections when allocatable
gnu size has a number of special cases regarding REL, RELA and STRTAB
sections being considered in size output. To avoid unnecessary
complexity this commit makes llvm size outputs these sections in cases
they have the SHF_ALLOC flag.

Differential Revision: https://reviews.llvm.org/D82479
2020-07-01 12:02:32 +01:00
Georgii Rymar
b18d8b7481 [llvm-readobj] - Don't crash when checking the number of dynamic symbols.
When we deriving the number of symbols from the DT_HASH table, we can crash when
calculate the number of symbols in the symbol table when SHT_DYNSYM
has sh_entsize == 0.

The patch fixes the issue.

Differential revision: https://reviews.llvm.org/D82877
2020-07-01 12:14:10 +03:00
Arthur Eubanks
5addf7faf9 [NewPM] Add explicit init value to -enable-new-pm
So it's easier to test with it on by default.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D82922
2020-06-30 18:40:01 -07:00
Sameer Arora
2f551c7741 [llvm-install-name-tool] Add -change option
Implement `-change` option for install-name-tool. The behavior exactly
matches that of cctools. Depends on D82410.

Reviewed By: jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D82613
2020-06-30 11:28:53 -07:00
Sameer Arora
c3265ed7a7 [llvm-install-name-tool] Add -id option
Implement `-id` option for install-name-tool. Differences from cctool's
behavior:
 - Does **NOT** throw an error if multiple -id options are specified.
    Instead, picks the last one.
 - Throws an error in case empty id is specified.

Reviewed By: jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D82410
2020-06-30 11:28:53 -07:00
Georgii Rymar
0d9f29a357 [yaml2obj] - Add a way to set default values for macros used in a YAML.
Currently we have to override all macros that are declared. But in many
cases it is convenient to use default values and to override only
a particular one or two.

This provides a way to set a default value for any macro:

```
Symbols:
  - Name: [[FOO=foo]]
```

Differential revision: https://reviews.llvm.org/D82455
2020-06-30 12:05:30 +03:00
Xing GUO
c9d3db94b5 [DWARFYAML][debug_info] Replace 'InitialLength' with 'Format' and 'Length'.
'InitialLength' is replaced with 'Format' (DWARF32 by default) and 'Length' in this patch.
Besides, test cases for DWARFv4 and DWARFv5, DWARF32 and DWARF64 is
added.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82622
2020-06-30 16:28:39 +08:00
Alexander Shaposhnikov
1130a0fbe6 [llvm-objcopy][MachO] Fix segment size alignment
This diff addresses the old TODO in MachOObjcopy.cpp and
correctly sets the page size used for alignment of segments.
In particular, now llvm-objcopy's output is consistent
with the input (the alignment of vmsize doesn't change).

Test plan:

1. make check-all
2. verify that a binary copied via llvm-objcopy now correctly works on iOS.

Differential revision: https://reviews.llvm.org/D82503
2020-06-29 23:55:21 -07:00
Bjorn Pettersson
79f2047cca [llvm-objcopy] Fix "unused-function" warning in NDEBUG builds
Fixup of commit b925ca37a8f28851 to allow building with
-Werror -Wunused-function.
2020-06-29 16:59:15 +02:00
Georgy Komarov
87e6a20dbb [llvm-objcopy] Emit error if removing symtab referenced by group section
SHT_GROUP sections contain a reference to a symbol indicating their
"signature" symbol. The symbol table containing this symbol is referred
to by the group section's sh_link field. If llvm-objcopy is instructed
to remove the symbol table, it will emit an error.

This fixes https://bugs.llvm.org/show_bug.cgi?id=46153.

Reviewed By: jhenderson, Higuoxing

Differential Revision: https://reviews.llvm.org/D82274
2020-06-29 10:42:03 +01:00
Alexander Shaposhnikov
1b6db69257 [llvm-install-name-tool] Add support for -rpath option
This diff implements -rpath option for llvm-install-name-tool
which replaces the rpath value in the specified Mach-O binary.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D82051
2020-06-26 17:23:03 -07:00
Vy Nguyen
052f666a48 [llvm-exegesis] Let Counter returns up to 16 entries
LBR contains (up to) 16 entries for last x branches and the X86LBRCounter (from D77422) should be able to return all those.
    Currently, it just returns the latest entry, which could lead to mis-leading measurements.
    This patch aslo changes the LatencyBenchmarkRunner to accommodate multi-value readings.

         https://reviews.llvm.org/D81050
2020-06-26 10:57:20 -04:00
Simon Pilgrim
08eb1e1f85 Add explicit Twine.h include to try and fix ICE on clang-ppc64be-linux 2020-06-26 14:14:09 +01:00
Zequan Wu
c7b0c37c92 [llvm-readobj][COFF] add .llvm.call-graph-profile section dump
Summary: Dumping contents of `.llvm.call-graph-profile` section of COFF in the same format as ELF.

Reviewers: jhenderson, MaskRay, hans

Reviewed By: jhenderson

Subscribers: grimar, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81894
2020-06-25 09:52:49 -07:00
Arthur Eubanks
c0c8bb0361 [NewPM] Separate out alias analysis passes in opt
Summary:
This somewhat matches the --aa-pipeline option, which separates out any
AA analyses to make sure they run before other passes.

Makes check-llvm failures under new PM go from 2356 -> 2303.

AA passes are not handled by PassBuilder::parsePassPipeline() but rather
PassBuilder::parseAAPipeline(), which is why this fixes some failures.

Reviewers: asbirlea, hans, ychen, leonardchan

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82488
2020-06-25 08:53:57 -07:00
Georgii Rymar
e7aef285a1 [llvm-readelf] - Report a warning instead of an error when dumping a broken section header.
There is no reason to report an error in `printSectionHeaders()`, we can report
a warning and continue dumping. This is what the patch does.

Differential revision: https://reviews.llvm.org/D82462
2020-06-25 14:38:06 +03:00
Arthur Eubanks
4cd332044f [NewPM][opt] Assert PassPipeline and Passes don't both contain passes
Reviewers: asbirlea

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82512
2020-06-24 18:00:22 -07:00
Sid Manning
9e71156d6d [Hexagon][llvm-objcopy] Add missing check for SHN_HEXAGON_SCOMMON_1
Differential Revision: https://reviews.llvm.org/D82484
2020-06-24 19:56:01 -05:00
Fangrui Song
b24b7c4c54 [llvm-profdata] --hot-func-list: fix some style issues in D81800
Reviewed By: wenlei, hoyFB

Differential Revision: https://reviews.llvm.org/D82500
2020-06-24 15:17:03 -07:00
weihe
4f72d6501a Add --hot-func-list to llvm-profdata show for sample profiles
Summary:
Add the --hot-func-list feature to llvm-profdata show for sample profiles. This feature prints a list of hot functions whose max sample count are above the 99% threshold, with their numbers of total samples, total samples percentage, max samples, entry samples, and their function names.

Test Plan:

Reviewers: wenlei, hoyFB

Reviewed By: wenlei, hoyFB

Subscribers: hoyFB, wenlei, weihe, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82355
2020-06-24 12:49:46 -07:00
Alexander Shaposhnikov
f1ab476248 [llvm-objcopy] Update help messages
This diff updates the help messages for llvm-objcopy, llvm-strip and
llvm-install-name-tool.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81907
2020-06-24 11:19:56 -07:00
Jonas Devlieghere
30a3e58d7c [llvm] Remove full stop frome error message
Address post-commit feedback from James Henderson in D80959.
2020-06-24 09:41:17 -07:00
Simon Pilgrim
e3b20aa31d Cloning.h - reduce AliasAnalysis.h include to forward declarations. NFC.
Fix implicit include dependencies in source files.
2020-06-24 15:48:10 +01:00
Georgii Rymar
2c089a8181 [llvm-readobj] - Don't crash when a broken GNU hash table is dumped with --hash-symbols.
Start using the `checkGNUHashTable` helper which was recently introduced to report
a proper warning when a GNU hash table goes past the end of the file.

Differential revision: https://reviews.llvm.org/D82449
2020-06-24 15:55:43 +03:00
Arthur Eubanks
39765fa3ed [NewPM] Attempt to run opt passes specified via -foo-pass under NPM
Summary:
In order to enable mass testing of opt under NPM, specifically passes
specified via -foo-pass.

This is gated under a new opt flag -enable-new-pm.  Currently
the pass flag parser looks for legacy PM passes with the name "foo" (for
opt arg "-foo") and creates a PassInfo for each one. Here we take the
(legacy PM) pass name and try to match it with one defined in (NPM)
PassRegistry.def.  Ultimately if we want all tests to pass like this,
we'll need to port all passes to NPM and register them in
PassRegistry.def under the same name as they were reigstered in the
legacy PM.

Maybe at some point we'll migrate all -foo to --passes=foo, but that
would be after the NPM switch.

Flipping on the flag causes 2XXX failures under check-llvm. By far most
of them are passes either not ported to NPM or don't have the same name
in PassRegistry.def as their old name.

Reviewers: hans, echristo, asbirlea, leonardchan

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82320
2020-06-23 10:10:40 -07:00
Simon Pilgrim
f6700f3e2e llvm-isel-fuzzer.cpp - fix implicit CommandLine.h dependency. NFC.
llvm-isel-fuzzer uses cl::opt but don't include CommandLine.h.
2020-06-23 12:29:53 +01:00
Simon Pilgrim
42915ef833 llvm-dwp.cpp - fix implicit CommandLine.h dependency. NFC.
llvm-dwp uses cl::opt + cl::list but don't include CommandLine.h.
2020-06-23 12:29:52 +01:00
Martin Storsjö
a862dd4d2e [llvm-rc] Implement the language id option
Differential Revision: https://reviews.llvm.org/D82265
2020-06-23 11:14:07 +03:00
Alexander Shaposhnikov
418d669e81 [llvm-install-name-tool] Implement delete_rpath option
This diff adds support for deleting an rpath from a Mach-O binary.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81527
2020-06-22 16:49:49 -07:00
Peter Collingbourne
7d1cbe5a8a llvm-nm: Implement --special-syms.
Differential Revision: https://reviews.llvm.org/D82251
2020-06-22 13:05:47 -07:00
Arthur Eubanks
7049eb9c94 [NPM] Bail out when -foo and --passes=foo are both specified
Summary:
Currently when --passes is used, any passes specified via -foo are
ignored. Explicitly bail out when that happens.

This requires changing some tests. Most were straightforward, but
codegenprepare-produced-address-math.ll is tricky. One of its RUNs runs
CodeGenPrepare. I tried porting CodeGenPrepare to the NPM, but ended up
getting stuck when I needed a TargetMachine. NPM doesn't have support
for MachineFunctions yet. So I just deleted that RUN line, since it was
mass-added in https://reviews.llvm.org/D54848 and is likely not that
useful.

Reviewers: echristo, hans

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82271
2020-06-22 08:27:13 -07:00
Georgii Rymar
9502f97d8b [llvm-readelf] - Do not crash when dumping the dynamic symbol table when its sh_entzize == 0.
We have a division by zero crash currently when
the sh_entzize of the dynamic symbol table is 0.

Differential revision: https://reviews.llvm.org/D82180
2020-06-22 15:41:34 +03:00
Georgii Rymar
d2790aee19 [llvm-readobj] - Validate the DT_STRSZ value to avoid crash.
It is possible to trigger a crash when a dynamic symbol has a
broken (too large) st_name and the DT_STRSZ is also broken.

We have the following code in the `Elf_Sym_Impl<ELFT>::getName`:

```
template <class ELFT>
Expected<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {
  uint32_t Offset = this->st_name;
  if (Offset >= StrTab.size())
    return createStringError(object_error::parse_failed,
                             "st_name (0x%" PRIx32
                             ") is past the end of the string table"
                             " of size 0x%zx",
                             Offset, StrTab.size());
...
```

The problem is that `StrTab` here is a `ELFDumper::DynamicStringTab` member
which is not validated properly on initialization. So it is possible to bypass the
`if` even when the `st_name` is huge.

This patch fixes the issue.

Differential revision: https://reviews.llvm.org/D82201
2020-06-22 15:24:59 +03:00
Momchil Velikov
a064519335 [LTO] Use StringRef instead of C-style strings in setCodeGenDebugOptions
Fixes an issue with missing nul-terminators and saves us some string
copying, compared to a version which would insert nul-terminators.

Differential Revision: https://reviews.llvm.org/D82033
2020-06-22 11:22:18 +01:00
Bruno Ricci
3b131a7452 Revert "Add --hot-func-list to llvm-profdata show for sample profiles"
This reverts commit 7348b951fe74f306970f6ac567fe5dddbb1c42d4.
It is causing Asan failures.
2020-06-21 14:33:08 +01:00
weihe
e6a186e4ac Add --hot-func-list to llvm-profdata show for sample profiles
Summary: Add the --hot-func-list feature to llvm-profdata show for sample profiles. This feature prints a list of hot functions whose max sample count are above the 99% threshold, with their numbers of total samples, total samples percentage, max samples, entry samples, and their function names.

Reviewers: wmi, hoyFB, wenlei

Reviewed By: wmi

Subscribers: hoyFB, wenlei, llvm-commits, weihe

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81800
2020-06-20 10:13:36 -07:00
Craig Topper
ef35532c13 [X86] Ignore bits 2:0 of the modrm byte when disassembling lfence, mfence, and sfence.
These are documented as using modrm byte of 0xe8, 0xf0, and 0xf8
respectively. But hardware ignore bits 2:0. So 0xe9-0xef is treated
the same as 0xe8. Similar for the other two.

Fixing this required adding 8 new formats to the X86 instructions
to convey this information. Could have gotten away with 3, but
adding all 8 made for a more logical conversion from format to
modrm encoding.

I renumbered the format encodings to keep the register modrm
formats grouped together.
2020-06-19 22:24:24 -07:00
Georgii Rymar
40767ae0bd [llvm-readobj] - Add a validation of the GNU hash table to printGnuHashHistogram().
Similar to D81937, we might crash when printing a histogram for a GNU hash table
with a 'symndx' index that is larger than the number of dynamic symbols.

This patch adopts and reuses the `getGnuHashTableChains()` helper which performs
a validation of the table. As a side effect the warning reported for
the --gnu-hash-table was improved.

Also with this change we start to report a warning when the histogram is requested for
the GNU hash table, but the dynamic symbols table is empty (size == 0).

Differential revision: https://reviews.llvm.org/D82010
2020-06-19 14:24:51 +03:00
Ronak Chauhan
735565a7a5 [MC] Pass the symbol rather than its name to onSymbolStart()
Summary: This allows targets to also consider the symbol's type and/or address if needed.

Reviewers: scott.linder, jhenderson, MaskRay, aardappel

Reviewed By: scott.linder, MaskRay

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, aheejin, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82090
2020-06-19 09:30:12 +05:30
Zequan Wu
7549421f49 [llvm-readobj] set --elf-cg-profile as alias of --cg-profile
Summary: Rename --elf-cg-profile to --cg-profile and keep --elf-cg-profile as an alias of --cg-profile.

Reviewers: jhenderson, MaskRay, espindola, hans

Reviewed By: jhenderson, MaskRay

Subscribers: emaste, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81855
2020-06-17 11:24:45 -07:00
Michał Górny
e37aaf4758 [llvm] Disable linking llvm-exegesis to dylib
Force linking llvm-exegesis to static LLVM libraries instead of dylib
to prevent duplicate symbols due to linking both.  Ideally, we'd want
to link to the dylib only here but the target sub-libraries use hidden
symbols from LLVM target libraries and therefore linking the dylib
fails.

Differential Revision: https://reviews.llvm.org/D81922
2020-06-17 19:00:26 +02:00
Michał Górny
1655e30934 [llvm] Avoid linking llvm-cfi-verify to duplicate libs
Fix the CMake rules for LLVMCFIVerify library not to pull duplicate
LLVM .a libraries when linking to the dylib.  This prevents problems
due to duplicate symbols and apparently fixes mingw32.

This is an alternative approach to D44650 that just forces .a libraries
instead.  However, there doesn't seem to be any reason to do that.

Differential Revision: https://reviews.llvm.org/D81921
2020-06-17 19:00:26 +02:00
Georgii Rymar
cdad2ab091 [llvm-readobj] - Do not crash when GnuHashTable->symndx is greater than the dynamic symbols count.
`Elf_GnuHash_Impl` has the following method:

```
ArrayRef<Elf_Word> values(unsigned DynamicSymCount) const {
  return ArrayRef<Elf_Word>(buckets().end(), DynamicSymCount - symndx);
}
```

When DynamicSymCount is less than symndx we return an array with the huge broken size.
This patch fixes the issue and adds an assert. This assert helped to fix an issue
in one of the test cases.

Differential revision: https://reviews.llvm.org/D81937
2020-06-17 14:26:36 +03:00
Georgii Rymar
4a931ed5b0 [llvm-readobj] - Split the printGnuHashTable(). NFCI.
`printGnuHashTable` contains the code to check the GNU hash table.
This patch splits it to `getGnuHashTableChains` helper
(and reorders slightly to reduce).

Differential revision: https://reviews.llvm.org/D81928
2020-06-17 14:13:51 +03:00
Fangrui Song
3ac41a5d21 [llvm-cov gcov] Don't suppress .gcov output if .gcda is corrupted
If .gcda is corrupted, gcov continues to produce a .gcov and just
assumes execution counts are zeros. This is reasonable, because the
program can corrupt its .gcda output. The code path should be similar to
the code path without .gcda.
2020-06-16 14:55:38 -07:00
Fangrui Song
d1d0909fd1 [gcov] Add -i --intermediate-format
Between gcov 4.9~8, `gcov -i $file` prints coverage information to
$file.gcov in an intermediate text format (single file, instead of
$source.gcov for each source file).

lcov newer than 2019-05-24 detects -i support and uses it to increase
processing speed.  gcov 9 (GCC r265587) removed --intermediate-format
and -i was changed to mean --json-format. However, we consider this
format still useful and support it. geninfo (part of lcov) supports this
format even if we announce that we are compatible with gcov 9.0.0
2020-06-16 14:14:28 -07:00
Fangrui Song
69837fa7b5 [gcov] Refactor llvm-cov gcov and add SourceInfo 2020-06-16 14:14:26 -07:00
Georgii Rymar
8609c64f9f [llvm-readelf] - Do not omit a zero symbol value when printing relocations.
Previously we only printed a symbol value when it has a non-empty name
or non-zero value.

This patch changes the behavior. Now we only omit a symbols value when
a relocation does not reference a symbol (i.e. symbol index == 0).

Seems it is what GNU readelf does, looking on its output.

Differential revision: https://reviews.llvm.org/D81842
2020-06-16 15:43:16 +03:00
Georgii Rymar
02574faddd [llvm-readelf] - Do not crash when relocation references a STT_SECTION symbol for the null section.
Currently, llvm-readelf crashes when there is a STT_SECTION symbol for the null section
and this symbol is used in a relocation.

Differential revision: https://reviews.llvm.org/D81840
2020-06-16 15:01:24 +03:00
Igor Kudrin
02872c9d70 [MC] Add --dwarf64 to generate DWARF64 debug info [1/7]
The patch adds an option `--dwarf64` to instruct a tool to generate
debug information in the 64-bit DWARF format. There is no real
implementation yet, only a few compatibility checks.

Differential Revision: https://reviews.llvm.org/D81143
2020-06-16 15:50:13 +07:00
Kirill Bobyrev
33517a77c3 NFC: Inline unused variable
The variable was not used anywhere except assert and causes build
warnings in the optimized builds.

Clanup after 913bc312b5516f0c7113fe14ea90097587ac5ca5
2020-06-16 08:29:52 +02:00
Alexander Shaposhnikov
3abfa57d76 [llvm-objcopy][MachO] Add support for LC_CODE_SIGNATURE
This diff adds support for copying binaries
containing a LC_CODE_SIGNATURE load command.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81768
2020-06-15 18:55:59 -07:00
Stanislav Mekhanoshin
9363e58d6d [AMDGPU] Add gfx1030 target
Differential Revision: https://reviews.llvm.org/D81886
2020-06-15 16:18:05 -07:00
Wouter van Oortmerssen
2eaa4e6cf6 [WebAssembly] Adding 64-bit version of R_WASM_MEMORY_ADDR_* relocs
This adds 4 new reloc types.

A lot of code that previously assumed any memory or offset values could be contained in a uint32_t (and often truncated results from functions returning 64-bit values) have been upgraded to uint64_t. This is not comprehensive: it is only the values that come in contact with the new relocation values and their dependents.

A new tablegen mapping was added to automatically upgrade loads/stores in the assembler, which otherwise has no way to select for these instructions (since they are indentical other than for the offset immediate). It follows a similar technique to https://reviews.llvm.org/D53307

Differential Revision: https://reviews.llvm.org/D81704
2020-06-15 10:07:42 -07:00
Xing GUO
deb304b59f Recommit "[DWARFYAML][debug_line] Replace InitialLength with Format and Length."
This recommits fcc0c186e9cea0af644581069058f0e00469d20e
2020-06-13 23:39:11 +08:00
Xing GUO
370f4bd1aa Revert "[DWARFYAML][debug_line] Replace InitialLength with Format and Length."
This reverts commit fcc0c186e9cea0af644581069058f0e00469d20e.
2020-06-13 17:57:02 +08:00
Xing GUO
8aff593f62 [DWARFYAML][debug_line] Replace InitialLength with Format and Length. 2020-06-13 17:47:06 +08:00
Ronak Chauhan
94e53ef1f1 [MC] Changes to help improve target specific symbol disassembly
Summary:
This commit slightly modifies the MCDisassembler, and llvm-objdump to
allow targets to also decode entire symbols.

WebAssembly uses the onSymbolStart hook it to decode preludes.
WebAssembly partially disassembles the symbol in its target specific
way; and then falls back to the normal flow of llvm-objdump.

AMDGPU needs it to decode kernel descriptors entirely, and move to the
next symbol.

This commit is to split the above task into 2.
- Changes to llvm-objdump and MC-layer without breaking WebAssembly code
  [ this commit ]
- AMDGPU's implementation of onSymbolStart that decodes kernel
  descriptors. [ https://reviews.llvm.org/D80713 ]

Reviewers: scott.linder, t-tye, sunfish, arsenm, jhenderson, MaskRay, aardappel

Reviewed By: scott.linder, jhenderson, aardappel

Subscribers: bcain, dschuff, wdng, tpr, sbc100, jgravelle-google, hiraditya, aheejin, MaskRay, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80512
2020-06-12 15:51:37 -04:00
Alexander Shaposhnikov
0f46c8ea11 [llvm-objcopy][MachO] Fix cmdsize of LC_RPATH
Fix the calculation of the field cmdsize (in the function buildRPathLoadCommand)
to account for the null byte terminator.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81575
2020-06-11 19:55:04 -07:00
Cyndy Ishida
fd46376e35 [llvm][llvm-nm] add TextAPI/MachO support
Summary:
This completes the needed glueing to support reading tbd files from nm.
This includes specifying which slice filtering with `--arch` and a new
option specifically for tbd files `--add-inlinedinfo` which will show
the reexported libraries that are appended in the tbd file.

Reviewers: ributzka, steven_wu, JDevlieghere, jhenderson

Reviewed By: JDevlieghere

Subscribers: hiraditya, MaskRay, dexonsmith, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81614
2020-06-11 18:54:16 -07:00
Fangrui Song
3ab1a8a75e [Support] Don't tie errs() to outs() by default
This reverts part of D81156.

Accessing errs() concurrently was safe before and racy after D81156.
(`errs() << 'a'` is always racy)

Accessing outs() and errs() concurrently was safe before and racy after D81156.

Don't tie errs() to outs() by default to fix the fallout.
llvm-dwarfdump is single-threaded and opting in the tie behavior is safe.
2020-06-11 15:19:56 -07:00
Reid Kleckner
6a61ba0a54 Re-land "Migrate the rest of COFFObjectFile to Error"
This reverts commit 101fbc01382edd89ea7b671104c68b30b2446cc0.

Remove leftover debugging attribute.

Update LLDB as well, which was missed before.
2020-06-11 14:46:16 -07:00
Fangrui Song
ee4cd89804 [llvm-objdump] Decrease instruction indentation for non-x86
Place the instruction at the 24th column (0-based indexing), matching
GNU objdump ARM/AArch64/powerpc/etc when the address is low.

This is beneficial for non-x86 targets which have short instruction
lengths.

```
// GNU objdump AArch64
   0:   91001062        add     x2, x3, #0x4
  400078:       91001062        add     x2, x3, #0x4
// llvm-objdump, with this patch
       0: 62 10 00 91   add     x2, x3, #4
  400078: 62 10 00 91   add     x2, x3, #4
// llvm-objdump, if we change to print a word instead of bytes in the future
       0: 91001062      add     x2, x3, #4
  400078: 91001062      add     x2, x3, #4

// GNU objdump Thumb
   0:   bf00            nop

// GNU objdump Power ISA 3.1 64-bit instruction
// 0:   00 00 10 04     plwa    r3,0
// 4:   00 00 60 a4
```

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D81590
2020-06-11 09:10:50 -07:00
Georgii Rymar
ed47bccbaf [yaml2obj] - Introduce a 10 Mb limit of the output by default and a --max-size option.
Multiple times we faced an issue of huge outputs due to unexpected behavior
or incorrect test cases. The last one was https://reviews.llvm.org/D80629#2073066.

This patch limits the output to 10 Mb for ELF and introduces the --max-size to change this
limit.

I've tried to keep the implementation non-intrusive.

The current logic we have is that we prepare section content in a buffer first and write
it to the output later. This patch checks the available limit on each writing attempt to this buffer
and stops writing when the limit is reached and raises the internal error flag.
Later, this flag is is checked before the actual writing to a file happens and
an error is reported.

Differential revision: https://reviews.llvm.org/D81258
2020-06-10 15:23:59 +03:00
Christopher Tetreault
3002df6d3f [SVE] Eliminate calls to default-false VectorType::get() from llvm-stress
Reviewers: efriedma, kmclaughlin, sdesmalen, MaskRay, JDevlieghere

Reviewed By: sdesmalen

Subscribers: tschuett, rkruppe, psnobl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81201
2020-06-08 11:32:37 -07:00
Benjamin Kramer
ce9aba2e75 SmallPtrSet::find -> SmallPtrSet::count
The latter is more readable and more efficient. While there clean up
some double lookups. NFCI.
2020-06-07 22:38:08 +02:00
Nico Weber
e905d3fcf1 Revert "Migrate the rest of COFFObjectFile to Error"
This reverts commit b5289656b865d2a73cf90819e20a96fb8414ab0b.
__attribute__((optnone)) doesn't build with msvc, see
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16326
2020-06-05 21:20:11 -04:00
Reid Kleckner
ce815b34d8 Migrate the rest of COFFObjectFile to Error 2020-06-05 16:29:05 -07:00
Alexandre Ganea
918e2e6d0d [llvm-pdbutil] Add missing --id-stats to dump the IPI stream
Before this patch, llvm-pdbutil supported only --type-stats to dump stats about a PDB TPI stream.
Adding --id-stats for completion.
2020-06-05 15:10:54 -04:00
Sameer Arora
17ff76fd0f [llvm-objcopy] Reorder --dump-section for MachO
Reorder `DumpSection` under `handleArgs` in file `MachOObjcopy.cpp`. The
operation to dump a section is now performed before both add and remove
section operations for MachO file format.

Change for the ELF format at D81097. Together fixes
https://bugs.llvm.org/show_bug.cgi?id=44283

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D81123
2020-06-05 10:49:22 -07:00
Sameer Arora
8c5b6feb6f [llvm-objcopy] Reorder --dump-section before --remove-section for ELF
Reorder `DumpSection` under `handleArgs` in file `ELFObjcopy.cpp`.
`DumpSection` is placed before `replaceAndRemoveSections` and is
therefore now the first operation under `handleArgs`. Thus, it is now
performed before both `add` and `remove` section operations.

Change for the MachO format at D81123. Together fixes https://bugs.llvm.org/show_bug.cgi?id=44283.

Reviewed By: alexshap, jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D81097
2020-06-05 10:45:51 -07:00
Sameer Arora
aadb0afb4a [llvm-ar] Update error messages and tests as per latest preferred style
It updates two error messages under `performOperation` in the file
llvm-ar.cpp. Furthermore, it also updates tests that print out these
error messages: `llvm/test/Object/ar-create.test` and
`llvm/test/tools/llvm-ar/print.test`.

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D80846
2020-06-05 10:37:26 -07:00
Jonas Devlieghere
b33381e799 [dsymutil] Don't emit N_AST symbol entries in the Mach-O companion file
Treat N_AST symbol table entries like other debug entries and don't emit
them in the linked binary.

Differential revision: https://reviews.llvm.org/D81205
2020-06-05 08:42:18 -07:00
Xing GUO
27bd788cf1 [DWARFYAML][debug_aranges] Replace InitialLength with Format and Length.
This patch addresses the comment in [D80972](https://reviews.llvm.org/D80972#inline-744217).

Before this patch, the initial length field of .debug_aranges section should be declared as:

```
## 32-bit DWARF
debug_aranges:
  - Length:
      TotalLength: 0x20
    Version: 2
    ...

## 64-bit DWARF
debug_aranges:
  - Length:
      TotalLength:   0xffffffff
      TotalLength64: 0x20
    Version: 2
    ...
```

After this patch:

```
## 32-bit DWARF
debug_aranges:
  - [[Format:  DWARF32]] ## Optional
    Length:  0x20
    Version: 2
    ...

## 64-bit DWARF
debug_aranges:
  - Format:  DWARF64
    Length:  0x20
    Version: 2
```

Current implementation of generating DWARF64 .debug_aranges section is buggy. A follow-up patch will improve it and add test cases for DWARF64.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D81063
2020-06-05 12:16:44 +08:00
Georgii Rymar
42f802871d [llvm-readelf] - Do not try to read past the end of the file when dumping the the SHT_GNU_HASH.
We have unobvious issue in the condition that is used to check
that we do not read past the EOF.

The problem is that the result of "GnuHashTable->nbuckets * 4" expression is uint32.
Because of that it was still possible to overflow it and pass the check.

There was no such problem with the "GnuHashTable->maskwords * sizeof(typename ELFT::Off)"
condition, because of `sizeof` on the right (which gives 64-bits value on x64),
but I've added an explicit conversion to 64-bit value for `GnuHashTable->maskwords` too.

Differential revision: https://reviews.llvm.org/D81103
2020-06-04 12:00:44 +03:00
Jonas Devlieghere
2b24554801 [llvm-dwarfdump] Print [=<offset>] after --debug-* options in help output.
Some of the --debug-* options can take an optional offset. Although the
man page does a good job of making that clear, it's much harder to
discover from the help output.

Currently the only reference to this is the following sentence:

> Where applicable these parameters take an optional =<offset> argument
> to dump only the entry at the specified offset.

This patch changes the help output from to print [=<offset>] after the
options that take an offset.

  --debug-info[=<offset>]    - Dump the .debug_info section

rdar://problem/63150066

Differential revision: https://reviews.llvm.org/D80959
2020-06-02 11:06:11 -07:00
Clement Courbet
0857d5bd0f [llvm-exegesis] Fix D80610.
Summary:
Using a .data() member on a StringRef was discarding the StringRef
size, breaking llvm-exegesis on machines with counter sums (e.g.
Zen2).

Reviewers: oontvoo

Subscribers: mstojanovic, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80982
2020-06-02 10:10:01 +02:00
Xing GUO
2955eebf43 [ObjectYAML][DWARF] Let dumpPubSection return DWARFYAML::PubSection.
Summary: This patch addresses comments in [D80722](https://reviews.llvm.org/D80722#inline-742353)

Reviewers: grimar, jhenderson

Reviewed By: grimar, jhenderson

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80861
2020-06-02 14:38:26 +08:00
Fangrui Song
18064a73bd [Object] Add DF_1_PIE
This flag (and the whole field DT_FLAGS_1) originated from Solaris. I intend to use it in an LLD patch D80872.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D80871
2020-06-01 08:56:02 -07:00
Georgii Rymar
516ffefcde [llvm-readelf] - Add explicit braces again. NFC.
Partially reverts feee98645dde4be31a70cc6660d2fc4d4b9d32d8.

Add explicit braces to a different place to fix
"error: add explicit braces to avoid dangling else [-Werror,-Wdangling-else]"
2020-06-01 13:10:16 +03:00
Georgii Rymar
c01c172f33 [llvm-readelf] - Add explicit braces. NFC.
Should fix the BB (http://lab.llvm.org:8011/builders/clang-ppc64le-rhel/builds/3907/steps/build%20stage%201/logs/stdio):

llvm-readobj/ELFDumper.cpp:4708:5: error: add explicit braces to avoid dangling else [-Werror,-Wdangling-else]
    else
    ^
2020-06-01 12:55:24 +03:00
Georgii Rymar
ac85d75310 [llvm-readobj] - Improve error reporting for hash tables.
This improves the next points for broken hash tables:

1) Use reportUniqueWarning to prevent duplication when
   --hash-table and --elf-hash-histogram are used together.

2) Dump nbuckets and nchain fields. It is often possible
   to dump them even when the table itself goes past the EOF etc.

Differential revision: https://reviews.llvm.org/D80373
2020-06-01 12:36:23 +03:00
Fangrui Song
16f18fc060 [llvm-objdump] Delete unneeeded namespace llvm {} 2020-05-30 18:03:43 -07:00
Fangrui Song
2b3d6eb517 [llvm-objdump] Move llvm:: to llvm::objdump:: and qualifying definitions with objdump::
Or adding `static`.

Qualifying definitions with `objdump::` comforms to the coding standards
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
2020-05-30 18:00:15 -07:00
Fangrui Song
5d4d16ee4e [llvm-objdump] Simplify reportError() and prepend outs().flush()
As noticed by dblaikie.

I don't know what code paths using reportError can cause stdout output
to be interleaved with stderr, so no test is added now.

Also drop an unneeded use of errs().fflush() in reportWarning().
I requested this in D64165.
2020-05-30 17:25:59 -07:00
Eric Christopher
aceb767487 Fix full unrolling with new pass manager.
Last we looked at this and couldn't come up with a reason to change
it, but with a pragma for full loop unrolling we bypass every other
loop unroll and then fail to fully unroll a loop when the pragma is set.

Move the OnlyWhenForced out of the check and into the initialization
of the full unroll pass in the new pass manager. This doesn't show up
with the old pass manager.

Add a new option to opt so that we can turn off loop unrolling
manually since this is a difference between clang and opt.

Tested with check-clang and check-llvm.
2020-05-29 20:08:21 -07:00
Ehud Katz
c0f1b37259 [PrintSCC] Fix printing a basic-block without a name
Print a basic-block as an operand to handle the case where it has no
name.

Differential Revision: https://reviews.llvm.org/D80552
2020-05-29 20:14:19 +03:00
Georgii Rymar
17fec031fa [llvm-readobj] - Cleanup the DwarfCFIEH::PrinterContext class. NFCI.
It would be nice to switch to `reportUniqueWarnings` from
`reportError` in this class, but first of all it needs a cleanup.

This patch:
1) Eliminates autos.
2) Removes code duplication.
3) Changes how the code works with `Expected<>`.
4) Introduces 2 new `using`s to make the code a bit shorter.

Differential revision: https://reviews.llvm.org/D80726
2020-05-29 16:45:18 +03:00
Igor Kudrin
c2113b68ec [llvm-objcopy][ELF] Fix removing a group member.
When a group member is removed, the corresponding record in the
SHT_GROUP section has to be deleted.

This fixes PR46064.

Differential Revision: https://reviews.llvm.org/D80568
2020-05-29 20:24:53 +07:00
Igor Kudrin
786d96db56 [llvm-objcopy][ELF] Fix removing SHT_GROUP sections.
When a SHT_GROUP section is removed, but other sections of the group are
kept, the SHF_GROUP flag of these sections should be dropped, otherwise
the resulting ELF file will be malformed.

Differential Revision: https://reviews.llvm.org/D80511
2020-05-29 20:24:53 +07:00
Xing GUO
8717026000 [ObjectYAML][DWARF] Make the PubSection optional.
This patch helps make the `PubSection` optional in the DWARF structure.

Reviewed By: jhenderson, aprantl

Differential Revision: https://reviews.llvm.org/D80722
2020-05-29 20:11:53 +08:00
Kadir Cetinkaya
6c544d572f [readobj] Fix dangling else warning 2020-05-29 12:55:25 +02:00
Georgii Rymar
dc3717d064 [llvm-readelf] - --elf-hash-histogram: do not crash when the .gnu.hash goes past the EOF.
llvm-readelf might crash when the .gnu.hash table goes past the EOF.

This patch splits and updates the code of a helper function `checkGNUHashTable`,
which is similar to `checkHashTable` and fixes the issue.

Differential revision: https://reviews.llvm.org/D80215
2020-05-29 13:29:48 +03:00
Lang Hames
4f5e68aaf3 [JITLink] Improve llvm-jitlink regression testing support for ELF.
This patch adds a jitlink pass, 'registerELFGraphInfo', that records section
and symbol information about each LinkGraph in the llvm-jitlink session object.
This allows symbols and sections to be referred to by name in llvm-jitlink
regression tests. This will enable a testcase to be written for
https://reviews.llvm.org/D80613.
2020-05-28 20:31:50 -07:00
Lang Hames
215d6e9284 [JITLink] Fix 80-column rule violation. 2020-05-28 20:31:50 -07:00
Arthur Eubanks
ad4217bf4c Run Coverage pass before other *San passes under new pass manager, round 2
Summary:
This was attempted once before in https://reviews.llvm.org/D79698, but
was reverted due to the coverage pass running in the wrong part of the
pipeline. This commit puts it in the same place as the other sanitizers.

This changes PassBuilder.OptimizerLastEPCallbacks to work on a
ModulePassManager instead of a FunctionPassManager. That is because
SanitizerCoverage cannot (easily) be split into a module pass and a
function pass like some of the other sanitizers since in its current
implementation it conditionally inserts module constructors based on
whether or not it successfully modified functions.

This fixes compiler-rt/test/msan/coverage-levels.cpp under the new pass
manager (last check-msan test).

Currently sanitizers + LTO don't work together under the new pass
manager, so I removed tests that checked that this combination works for
sancov.

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D80692
2020-05-28 17:04:47 -07:00
Arthur Eubanks
ce6bb928cc Revert "Run Coverage pass before other *San passes under new pass manager, round 2"
This reverts commit 922fa2fce38b0bd97921b91ff1cdc57f18d3569c.
2020-05-28 14:38:05 -07:00
Arthur Eubanks
d743388d68 Run Coverage pass before other *San passes under new pass manager, round 2
Summary:
This was attempted once before in https://reviews.llvm.org/D79698, but
was reverted due to the coverage pass running in the wrong part of the
pipeline. This commit puts it in the same place as the other sanitizers.

This changes PassBuilder.OptimizerLastEPCallbacks to work on a
ModulePassManager instead of a FunctionPassManager. That is because
SanitizerCoverage cannot (easily) be split into a module pass and a
function pass like some of the other sanitizers since in its current
implementation it conditionally inserts module constructors based on
whether or not it successfully modified functions.

This fixes compiler-rt/test/msan/coverage-levels.cpp under the new pass
manager (last check-msan test).

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D80692
2020-05-28 14:25:23 -07:00
Vy Nguyen
86e59df733 [llvm-exegesis] Make a few counter methods virtual to allow targets to provide target-specific support.
Misc: Also include errno in failure message.

Differential Revision: https://reviews.llvm.org/D80610
2020-05-28 12:38:25 -04:00
Simon Pilgrim
5b2222b080 SymbolicFile.h - removed unused FileSystem.h include. NFC.
Exposes a number of implicit dependencies that needs fixing in source files and XCOFFObjectFile.h.
2020-05-28 15:26:31 +01:00
Simon Pilgrim
20177dfe57 llvm-dwarfdump.h - remove unnecessary WithColor.h include. NFC. 2020-05-28 13:03:18 +01:00
Kazushi (Jam) Marukawa
3398257fcd [VE] Implements minimum MC layer for VE (3/4)
Summary:
Define ELF binary code for VE and modify code where should use this new code.

Depends on D79544.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79545
2020-05-28 10:07:48 +02:00
Michael Liao
471e025d5e Fix -Wpedantic warning. NFC. 2020-05-27 15:57:03 -04:00
Simon Pilgrim
ad901cfbf0 CoverageFilters.h - reduce unnecessary includes to forward declarations. NFC. 2020-05-27 16:57:47 +01:00
Georgii Rymar
dc0839500a [llvm-readobj] - Do not crash when an invalid .eh_frame_hdr is dumped using --unwind.
When the p_offset/p_filesz of the PT_GNU_EH_FRAME is invalid
(e.g larger than the file size) then llvm-readobj might crash.

This patch fixes the issue. I've introduced `ELFFile<ELFT>::getSegmentContent`
method, which is very similar to `ELFFile<ELFT>::getSectionContentsAsArray` one.

Differential revision: https://reviews.llvm.org/D80380
2020-05-27 16:41:09 +03:00
Georgii Rymar
c83e5f565f [llvm-readelf] - Split GNUStyle<ELFT>::printHashHistogram. NFC.
As was mentioned in review comments for D80204,
`printHashHistogram` has 2 lambdas that are probably too large
and deserves splitting into member functions.

This patch does it.

Differential revision: https://reviews.llvm.org/D80546
2020-05-27 13:59:20 +03:00
Georgii Rymar
2dcffa66b5 [llvm-readobj] - Do not skip building of the GNU hash table histogram.
When the `--elf-hash-histogram` is used, the code first tries to build
a histogram for the .hash table and then for the .gnu.hash table.

The problem is that dumper might return early when unable or do not need to
build a histogram for the .hash.

This patch reorders the code slightly to fix the issue and adds a test case.

Differential revision: https://reviews.llvm.org/D80204
2020-05-27 13:46:41 +03:00
Alexander Shaposhnikov
372d313844 [llvm-objcopy][MachO] Add support for removing Swift symbols
cctools strip has the option "-T" which removes Swift symbols.
This diff implements this option in llvm-strip for MachO.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D80099
2020-05-26 16:49:56 -07:00
Vitaly Buka
69b7763e54 [sancov] Accommodate sancov and coverage report server for use under Windows
Summary:
This patch makes the following changes to SanCov and its complementary Python script in order to resolve issues pertaining to non-UNIX file paths in JSON symbolization information:
* Convert all paths to use forward slash.
* Update `coverage-report-server.py` to correctly handle paths to sources which contain spaces.
* Remove Linux platform restriction for all SanCov unit tests. All SanCov tests passed when ran on my local Windows machine.

Patch by Douglas Gliner.

Reviewers: kcc, filcab, phosek, morehouse, vitalybuka, metzman

Reviewed By: vitalybuka

Subscribers: vsk, Dor1s, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D51018
2020-05-26 14:36:44 -07:00
Jonas Devlieghere
1f4b52bb8f [dsymutil] Escape CFBundleIdentifier in plist.
Revision 333565 started escaping HTML special characters in the plist
written by dsymutil, but didn't include the updated CFBundleIdentifier.
2020-05-26 09:38:32 -07:00
Marek Kurdej
5b5d7d8bc7 [CMake] Fix typos. NFC 2020-05-22 14:40:43 +02:00
Dominic Chen
d0062bc792 [llvm-extract] Fix basic block extraction by delaying search until the function is materialized
Summary: When I try to extract a basic block using llvm-extract, it erroneously reports that the named basic block doesn't exist. After digging into the code, it appears to be iterating over an unmaterialized function, which will fail to match any basic blocks.

Reviewers: volkan, qcolombet

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80346
2020-05-21 21:18:37 -04:00
Dominic Chen
69d36b0ea5 llvm-diff: Avoid crash with complex expressions
Summary: With complex IR, the difference engine can enter an inconsistent state where the instruction and block difference engines return different results. Prevent a crash by refusing to pop beyond the end of the vector.

Reviewers: rjmccall

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80351
2020-05-21 17:43:47 -04:00
Jonas Devlieghere
e5fd992382 [dsymutil] Add llvm_unreachable to silence warning
Fixes warning: control reaches end of non-void function [-Wreturn-type]
2020-05-21 12:27:52 -07:00
Jonas Devlieghere
435f397d00 [dsymutil] Fix conversion between unique_ptr and Expected
Reproducer.cpp:70:12: error: could not convert ‘Repro’ from
‘std::unique_ptr<llvm::dsymutil::ReproducerGenerate,
std::default_delete<llvm::dsymutil::ReproducerGenerate> >’ to
‘llvm::Expected<std::unique_ptr<llvm::dsymutil::Reproducer> >’
2020-05-21 11:42:04 -07:00
Jonas Devlieghere
c85ea496cb [dsymutil] Fix include-style 2020-05-21 11:19:57 -07:00
Jonas Devlieghere
b03521b98d [dsymutil] Add reproducers to dsymutil
Add support for generating a dsymutil reproducer. The result is a folder
containing all the object files for linking.

When --gen-reproducer is passed, dsymutil uses a FileCollectorFileSystem
which keeps track of all the files used by dsymutil. These files are
copied into a temporary directory when dsymutil exists.

When this path is passed to --use-reproducer, dsymutil uses a
RedirectingFileSystem that will use the files from the reproducer
directory instead of the actual paths. This means you don't need to mess
with the OSO path prefix.

Differential revision: https://reviews.llvm.org/D79398
2020-05-21 10:59:49 -07:00
Nico Weber
6863d97f67 Give microsoftDemangle() an outparam for how many input bytes were consumed.
Demangling Itanium symbols either consumes the whole input or fails,
but Microsoft symbols can be successfully demangled with just some
of the input.

Add an outparam that enables clients to know how much of the input was
consumed, and use this flag to give llvm-undname an opt-in warning
on partially consumed symbols.

Differential Revision: https://reviews.llvm.org/D80173
2020-05-20 16:17:31 -04:00
Benjamin Kramer
f7c7ec9b72 [gold-plugin] Unbreak the build after d9b9ce6c04764275a23cd0cf1856a35aae921af7 2020-05-20 11:56:06 +02:00
Simon Pilgrim
23ca92af1f CommandFlags.h - remove unnecessary includes. NFC.
Replace with forward declarations and move necessary includes down to source files.

Exposes an implicit dependency on TargetMachine.h in llvm-opt-fuzzer.cpp
2020-05-20 09:58:37 +01:00
Georgii Rymar
11f7be54a0 [yaml2obj] - Stop using square brackets for unique suffixes.
For describing section/symbol names we can use unique suffixes,
e.g:

```
- Name: '.foo [1]`
- Name: '.foo [2]`
```

It can be a problem (see https://reviews.llvm.org/D79984#inline-734829),
because `[]` are sometimes used to describe a macros:

```
- Name: "[[a0]]"
```

Seems the better approach is to use something else, like "()".
This patch does it and refactors the code related.

Differential revision: https://reviews.llvm.org/D80123
2020-05-19 12:59:13 +03:00
Craig Topper
0fe1404812 Fix several places that were calling verifyFunction or verifyModule without checking the return value.
verifyFunction/verifyModule don't assert or error internally. They
also don't print anything if you don't pass a raw_ostream to them.
So the caller needs to check the result and ideally pass a stream
to get the messages. Otherwise they're just really expensive no-ops.

I've filed PR45965 for another instance in SLPVectorizer
that causes a lit test failure.

Differential Revision: https://reviews.llvm.org/D80106
2020-05-18 13:28:46 -07:00
Jonas Devlieghere
028966e9eb [dsymutil] Make sure the --help output and man page are consistent
As suggested by Adrian in D79398.
2020-05-18 11:38:36 -07:00
Alexander Shaposhnikov
742719477a [llvm-objcopy][MachO] Fix code formatting
Apply clang-format to MachOObjcopy.cpp. NFC.

Test plan: make check-all
2020-05-17 20:46:17 -07:00
Fedor Sergeev
25a434ada5 Add missing include Host.h in llvm-mc-* fuzzers. NFC.
Fixes build failure in these fuzzers.
2020-05-18 02:21:22 +07:00
Simon Pilgrim
9aba16961d Revert rGca18ce1a00cd8b7cb7ce0e130440f5ae1ffe86ee "GlobPattern.h - remove unnecessary BitVector.h/StringRef.h includes. NFC"
Causes lld build errors
2020-05-17 18:51:21 +01:00
Simon Pilgrim
dc62775ff9 GlobPattern.h - remove unnecessary BitVector.h/StringRef.h includes. NFC
Use forward declarations (BitVector already had one) and an headers to source file that were implicitly using them.
2020-05-17 18:29:41 +01:00
Christopher Tetreault
7b3e2debb8 [SVE] Restore broken LLVM-C ABI compatability
Reviewers: deadalnix, efriedma, rengolin, jyknight, joerg

Reviewed By: joerg

Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79915
2020-05-15 11:50:24 -07:00
James Henderson
b3debca76f Fix Linux build broken by f06e6564 2020-05-15 15:36:26 +01:00
James Henderson
ae0c7ca96e [llvm-readobj] Implement --dependent-libraries for GNU output
Previously, the option was only implemented for LLVM output. This fixes
https://bugs.llvm.org/show_bug.cgi?id=45695.

At the current time, GNU readelf does not support this option.
Consequently, this patch simply attempts to roughly follow the output
style for similar options like --syms/--notes etc, combined with
--string-dump output.

Reviewed by: MaskRay, grimar

Differential Revision: https://reviews.llvm.org/D79939
2020-05-15 15:11:22 +01:00
Ties Stuij
745a9668d4 [IR][BFloat] Add BFloat IR type
Summary:
The BFloat IR type is introduced to provide support for, initially, the BFloat16
datatype introduced with the Armv8.6 architecture (optional from Armv8.2
onwards). It has an 8-bit exponent and a 7-bit mantissa and behaves like an IEEE
754 floating point IR type.

This is part of a patch series upstreaming Armv8.6 features. Subsequent patches
will upstream intrinsics support and C-lang support for BFloat.

Reviewers: SjoerdMeijer, rjmccall, rsmith, liutianle, RKSimon, craig.topper, jfb, LukeGeeson, sdesmalen, deadalnix, ctetreau

Subscribers: hiraditya, llvm-commits, danielkiss, arphaman, kristof.beyls, dexonsmith

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78190
2020-05-15 14:43:43 +01:00
Georgii Rymar
08e2edb9fd [DebugInfo] - DWARFDebugFrame: do not call abort() on errors.
Imagine we have a broken .eh_frame.
Below is a possible sample output of llvm-readelf:

```
...
    entry 2 {
      initial_location: 0x10f5
      address: 0x2080
    }
  }
}
.eh_frame section at offset 0x2028 address 0x2028:
LLVM ERROR: Parsing entry instructions at 0 failed
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /home/umb/LLVM/LLVM/llvm-project/build/bin/llvm-readelf -a 1
 #0 0x000055f4a2ff5a1a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/umb/LLVM/LLVM/llvm-project/build/bin/llvm-readelf+0x2b9a1a)
...
#15 0x00007fdae5dc209b __libc_start_main /build/glibc-B9XfQf/glibc-2.28/csu/../csu/libc-start.c:342:3
#16 0x000055f4a2db746a _start (/home/umb/LLVM/LLVM/llvm-project/build/bin/llvm-readelf+0x7b46a)
Aborted
```

I.e. it calls abort(), suggests to submit a bug report and exits with the code 134.
This patch changes the logic to propagate errors to callers.
This fixes the behavior for llvm-dwarfdump, llvm-readobj and other possible tools.

Differential revision: https://reviews.llvm.org/D79165
2020-05-15 13:05:35 +03:00
Georgii Rymar
6f3dbacc03 [llvm-readobj] - --gnu-hash-table: do not crash when the GNU hash table goes past the EOF.
We might have a scenario where a the `GbuHashTable` variable correctly points
to a place inside the file (we validate this fact early in `parseDynamicTable`),
but nbuckets/maskwords fields are broken in the way the code tries
to read the data past the EOF. This patch fixes the issue.

Differential revision: https://reviews.llvm.org/D79853
2020-05-15 11:33:23 +03:00
Hubert Tong
26b71d54fd Speculative fix for build breakage from D78403
D78403 appears responsible for breaking bots:
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/12261/steps/build%20stage%201/logs/stdio
2020-05-14 23:57:22 -04:00
Eli Friedman
f5d3346387 Infer alignment of unmarked loads in IR/bitcode parsing.
For IR generated by a compiler, this is really simple: you just take the
datalayout from the beginning of the file, and apply it to all the IR
later in the file. For optimization testcases that don't care about the
datalayout, this is also really simple: we just use the default
datalayout.

The complexity here comes from the fact that some LLVM tools allow
overriding the datalayout: some tools have an explicit flag for this,
some tools will infer a datalayout based on the code generation target.
Supporting this properly required plumbing through a bunch of new
machinery: we want to allow overriding the datalayout after the
datalayout is parsed from the file, but before we use any information
from it. Therefore, IR/bitcode parsing now has a callback to allow tools
to compute the datalayout at the appropriate time.

Not sure if I covered all the LLVM tools that want to use the callback.
(clang? lli? Misc IR manipulation tools like llvm-link?). But this is at
least enough for all the LLVM regression tests, and IR without a
datalayout is not something frontends should generate.

This change had some sort of weird effects for certain CodeGen
regression tests: if the datalayout is overridden with a datalayout with
a different program or stack address space, we now parse IR based on the
overridden datalayout, instead of the one written in the file (or the
default one, if none is specified). This broke a few AVR tests, and one
AMDGPU test.

Outside the CodeGen tests I mentioned, the test changes are all just
fixing CHECK lines and moving around datalayout lines in weird places.

Differential Revision: https://reviews.llvm.org/D78403
2020-05-14 13:03:50 -07:00
Xing GUO
388be5a474 [llvm-dwarfdump] Make commandline arguments consistent.
Currently, llvm-dwarfdump's help message has two issues.

1. Most long options are printed in `--long-option`, except for some section dumping options, e.g., `-apple-names`, `-debug-addr`.

2. Most options are printed with consistent indention, except for some section dumping options.

This patch helps resolve these two issues.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79618
2020-05-14 17:34:50 +08:00
Greg Clayton
a6a42f2f8d Fix buildbots errors after comitting D78782.
Rename "Ranges" variables to "DebugRanges" to avoid warnings/errors on machines that have extra settings enabled.

https://reviews.llvm.org/D78782
2020-05-13 22:01:57 -07:00
Greg Clayton
a6406225b4 Add .debug_ranges support to the DWARF YAML.
Summary: This allows DIEs with DW_AT_ranges to be encoded and decoded _and_ actually have their address ranges be included instead of having DW_AT_ranges with a section offset value for a section that doesn't exist.

Reviewers: labath, aprantl, JDevlieghere, dblaikie, probinson

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78782
2020-05-13 16:21:45 -07:00
Amy Huang
48fecb2d18 [NativeSession] Implement NativeSession::findSymbolByAddress.
Summary: This implements searching for function symbols and public symbols by address.

More specifically,
-Implements NativeSession::findSymbolByAddress for function symbols and
public symbols. I think data symbols are also searched for, but isn't
implemented in this patch.
-Adds classes for NativeFunctionSymbol and NativePublicSymbol
-Adds a '-use-native-pdb-reader' option to llvm-symbolizer, for testing
purposes.

Reviewers: rnk, amccarth, labath

Subscribers: mgorny, hiraditya, MaskRay, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79269
2020-05-13 09:39:25 -07:00
Wei Mi
44bffa48c2 [SampleFDO] Rename llvm-profdata flag -partial-profile to -gen-partial-profile.
The internal flag -partial-profile in llvm conflicts with the flag with
the same name in llvm-profdata. The conflict happens in builds with
LLVM_LINK_LLVM_DYLIB enabled. In this case the tools are linked with libLLVM
and we end up with two definitions for the same cl::opt.

The patch renames llvm-profdata flag -partial-profile to -gen-partial-profile.
2020-05-12 15:06:03 -07:00
Fangrui Song
5ac915ed2c [gcov] Implement --stdout -t
gcov by default prints to a .gcov file. With --stdout, stdout is used.
Some summary information is omitted. There is no separator for multiple
source files.
2020-05-10 21:02:38 -07:00
Fangrui Song
d7b402943b [gcov] Fix .gcda decoding and support GCC 8, 9 and 10
GCDAProfiling.c unnecessarily writes function names to .gcda files.
GCC 4.2 gcc/libgcov.c (now renamed to libgcc/libgcov*) did not write function
names. gcov-7 (compatible) crashes on .gcda produced by libclang_rt.profile
rL176173 realized the problem and introduced a mode to remove function
names.

llvm-cov code apparently takes GCDAProfiling.c output format as truth
and tries to decode function names.  Additionally, llvm-cov tries to
decode tags in certain order which does not match libgcov emitted .gcda
files.

This patch fixes the .gcda decoder and makes it work with GCC 8 and 9
(10 is compatible with 9). Note, line statistics are broken and not
fixed by this patch.

Add test/tools/llvm-cov/gcov-{4.7,8,9}.c to test compatibility.
2020-05-10 09:55:23 -07:00
Reid Kleckner
24ad5a39c5 [COFF] Migrate COFFObjectFile to Expected<T>
I noticed that std::error_code() does one-time initialization. Avoid
that overhead with Expected<T> and llvm::Error. Also, it is consistent
with the virtual interface and ELF, and generally cleaner.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D79643
2020-05-08 14:01:39 -07:00
Fangrui Song
880f863489 Reland D79501 "[DebugInfo] Fix handling DW_OP_call_ref in DWARF64 units."
With a fix to uninitialized EndOffset.

DW_OP_call_ref is the only operation that has an operand which depends
on the DWARF format. The patch fixes handling that operation in DWARF64
units.

Differential Revision: https://reviews.llvm.org/D79501
2020-05-08 09:35:54 -07:00
Krasimir Georgiev
3f7e709012 Revert "[DebugInfo] Fix handling DW_OP_call_ref in DWARF64 units."
This reverts commit 989ae9e848a079715c2d23e5d3622cac9b48e08e.

Newly added test fails:
FAIL: LLVM::DW_OP_call_ref_unexpected.s

http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/28298
2020-05-08 17:24:32 +02:00
Igor Kudrin
94e656da18 [DebugInfo] Fix handling DW_OP_call_ref in DWARF64 units.
DW_OP_call_ref is the only operation that has an operand which depends
on the DWARF format. The patch fixes handling that operation in DWARF64
units.

Differential Revision: https://reviews.llvm.org/D79501
2020-05-08 15:14:42 +07:00
Jonas Devlieghere
5e66aeab68 [dsymutil] Add option to print statistics about the .debug_info size.
This patch adds statistics about the contribution of each object file to
the linked debug info. When --statistics is passed to dsymutil, it
prints a table after linking as illustrated below.

It lists the object file name, the size of the debug info in the object
file in bytes, and the absolute size contribution to the linked dSYM and
the percentage difference. The table is sorted by the output size, so
the object files contributing the most to the link are listed first.

.debug_info section size (in bytes)
-------------------------------------------------------------------------------
Filename                                           Object         dSYM   Change
-------------------------------------------------------------------------------
basic2.macho.x86_64.o                                210b         165b  -24.00%
basic3.macho.x86_64.o                                177b         150b  -16.51%
basic1.macho.x86_64.o                                125b         129b    3.15%
-------------------------------------------------------------------------------
Total                                                512b         444b  -14.23%
-------------------------------------------------------------------------------

Differential revision: https://reviews.llvm.org/D79513
2020-05-06 19:48:45 -07:00
Reid Kleckner
9c4905d77b [COFF] Dump string table size for COFF file headers
I couldn't find this info in any other dumper, so it might as well be
here.
2020-05-06 15:48:36 -07:00
Xing GUO
7653f25b98 [llvm-nm/objdump/size] Add tests for dumping symbol tables with invalid sh_size.
This change adds tests for llvm-nm, llvm-objdump and llvm-size when dumping symbol tables with invalid sh_size (sh_size % sizeof(Elf_Sym) != 0).

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D77864
2020-05-06 17:01:20 +08:00
Wenlei He
e88b44e49c [llvm-profdata] Support -detailed-summary for Sample Profile
Summary: Add -detailed-summary support for sample profile dump to match that of instrumentation profile.

Reviewers: wmi, davidxl, hoyFB

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79291
2020-05-05 18:28:22 -07:00
Fangrui Song
4e41eb3f79 [llvm-objcopy][ELF] Allow --dump-section to dump an empty non-SHT_NOBITS section
This is the ELF part of D75949.

GNU objcopy from binutils 2.35 onwards will support an empty non-SHT_NOBITS section as
well
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e052e2ba295a65b6ea80cbc3f90495beca299c42

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79339
2020-05-05 08:26:34 -07:00
Jonas Devlieghere
6f1978ec1f [dsymutil] Thread the VFS through dsymutil (NFC)
This patch threads the virtual file system through dsymutil.

Currently there is no good way to find out exactly what files are
necessary in order to reproduce a dsymutil link, at least not without
knowledge of how dsymutil's internals.  My motivation for this change is
to add lightweight "reproducers" that automatically gather the input
object files through the FileCollectorFileSystem. The files together
with the YAML mapping will allow us to transparently reproduce a
dsymutil link, even without having to mess with the OSO path prefix.

Differential revision: https://reviews.llvm.org/D79376
2020-05-04 20:21:33 -07:00
Zakk Chen
6bb0aa513e [LTO] Suppress emission of empty combined module by default
Summary:
That unless the user requested an output object (--lto-obj-path), the an
unused empty combined module is not emitted.

This changed is helpful for some target (ex. RISCV-V) which encoded the
ABI info in IR module flags (target-abi). Empty unused module has no ABI
info so the linker would get the linking error during merging
incompatible ABIs.

Reviewers: tejohnson, espindola, MaskRay

Subscribers: emaste, inglorion, arichardson, hiraditya, simoncook, MaskRay, steven_wu, dexonsmith, PkmX, dang, lenary, s.egerton, luismarques, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78988
2020-05-04 18:31:09 -07:00
Lang Hames
7864e622b1 [ORC] Rename SearchOrder operations on JITDylib to LinkOrder.
Refering to the link order of a dylib better matches the terminology used in
static compilation. As upcoming patches will increase the number of places where
link order matters (for example when closing JITDylibs) it's better to get this
name change out of the way early.
2020-05-04 16:47:52 -07:00
Fangrui Song
d4f7430fcd [llvm-objdump][ARM] Print inline relocations when dumping ARM data
Fixes PR44357

For ARM ELF, regions covered by data mapping symbols `$d` are dumped as `.byte`, `.short` or `.word` but inline relocations are not printed. This patch merges its loop into the normal instruction printing loop so that inline relocations are printed.

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D79284
2020-05-04 11:51:39 -07:00
Djordje Todorovic
c074cdefc8 [llvm-dwarfdump][Stats] Clean up
This addresses:
  -Clean up the source code
  -Refactor the JSON fields
  -Fix the test cases
  -Improve the docs for the stats output

Differential Revision: https://reviews.llvm.org/D77789
2020-05-04 09:35:40 +02:00
Fangrui Song
cf2a6f9195 [llvm-objcopy] Avoid invalid Sec.Offset after D79229
To avoid undefined behavior caught by -fsanitize=undefined on binary-paddr.test

  void SectionWriter::visit(const Section &Sec) {
    if (Sec.Type != SHT_NOBITS)
      // Sec.Contents is empty while Sec.Offset may be out of bound
      llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset);
  }
2020-05-03 21:57:51 -07:00
Benjamin Kramer
5f955966e5 Don't stash types that aren't copyable or moveable into a SmallVector
This seems to be working by accident.
2020-05-02 19:13:06 +02:00
Sam McCall
9e1817bf4e std::isspace -> llvm::isSpace (where locale should be ignored)
I've left out some cases where I wasn't totally sure this was right or
whether the include was ok (compiler-rt) or idiomatic (flang).
2020-05-02 15:36:04 +02:00
Xing GUO
0cc48af0ab [Object] Change ObjectFile::getSymbolValue() return type to Expected<uint64_t>
Summary:
In D77860, we have changed `getSymbolFlags()` return type to `Expected<uint32_t>`.
This change helps bubble the error further up the stack.

Reviewers: jhenderson, grimar, JDevlieghere, MaskRay

Reviewed By: jhenderson

Subscribers: hiraditya, MaskRay, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79075
2020-05-02 14:04:44 +08:00
Alexander Shaposhnikov
c5ebacd65c [llvm-objcopy][MachO] Fix isExternalSymbol method
N_PEXT bit should not affect whether a symbol is considered to be external or not.
This also fixes the construction of the symbol table since it relies on the correct
ordering of symbols.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78888
2020-05-01 18:22:35 -07:00
Fangrui Song
4ae6ca1cf2 [llvm-objcopy] -O binary: skip empty sections
After SHF_ALLOC sections are ordered by LMA:

* If initial sections are empty, GNU objcopy skips their contents while we
  emit leading zeros. (binary-paddr.test %t4)
* If trailing sections are empty, GNU objcopy skips their contents while we
  emit trailing zeros. (binary-paddr.test %t5)

This patch matches GNU objcopy's behavior. Linkers don't keep p_memsz
PT_LOAD segments. Such empty sections would not have a containing
PT_LOAD and `Section::ParentSegment` might be null if linkers fail to
optimize the file offsets (lld D79254).

In particular, without D79254, the arm Linux kernel's multi_v5_defconfig
depends on this behavior: in `vmlinux`, an empty .text_itcm is mapped at
a very high address (0xfffe0000) but the kernel does not expect
`objcopy -O binary` to create a very large `arch/arm/boot/Image`
(0xfffe0000-0xc0000000 ~= 1GiB). See https://bugs.llvm.org/show_bug.cgi?id=45632

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79229
2020-05-01 14:25:37 -07:00
Georgii Rymar
b46eefe880 [llvm-readobj] - Simplify conditions used for printing segment mappings. NFCI.
This patch is a NFC refactoring.

Currently the logic is overcomplicated, contains dead conditions and is very hard to read.
This patch performs a very straightforward simplification. Probably it can be
simplified and improved more, but we need to land test cases documenting/testing
all the current functionality first.

Differential revision: https://reviews.llvm.org/D78709
2020-05-01 18:57:09 +03:00
Georgii Rymar
e1adf90ced [llvm-readelf] - Do not crash when the PT_INTERP has a broken offset.
We do not verify the p_offset of the PT_INTERP header and tool may
crash when a program interpreter name string goes past the end of the file.

Differential revision: https://reviews.llvm.org/D79013
2020-05-01 18:51:46 +03:00
Jay Foad
a751830308 Fix indentation. NFC. 2020-05-01 11:38:07 +01:00
Martin Storsjö
579a3edad4 [llvm-objcopy] [COFF] Fix a misconception about debug directory payloads
The debug directory payload is not located directly after the
debug directory entry itself, but can essentially be located anywhere
in the binary (even outside of mapped sections, although we don't
handle that case).

Differential Revision: https://reviews.llvm.org/D78921
2020-04-29 20:35:36 +03:00
Martin Storsjö
f4aa425c92 [llvm-readobj] [COFF] Cope with debug directory payloads in unmapped areas
According to the spec, the payload for debug directories can be
in parts of the binary that aren't mapped at runtime - in these
cases, AddressOfRawData is just set to zero.

Differential Revision: https://reviews.llvm.org/D78920
2020-04-29 20:35:33 +03:00
Xing GUO
9e66c35e52 [dsymutil] Fix short options displayed in the help message.
This patch helps make the short options displayed in the help message be consistant with the description in https://llvm.org/docs/CommandGuide/dsymutil.html

Reviewed By: JDevlieghere, aprantl

Differential Revision: https://reviews.llvm.org/D78476
2020-04-29 10:20:13 +08:00
Saleem Abdulrasool
11c3ff3b6b Revert "Temporarily revert "build: use find_package(Python3) if available""
This reverts commit 35edd704e0fda09e8e634515c0b451d4a8b6b914.

Revert the revert and extend the patch further to account for the use of
the `PYTHONINTERP_FOUND`.
2020-04-29 01:38:08 +00:00
Eric Christopher
360f35ba0b Temporarily revert "build: use find_package(Python3) if available"
as it seems to be causing multiple people problems with running tests
and building.

This reverts commit c4c3883b00d3a6aa657a5e3e515c90c9ea1f81c6.
2020-04-28 16:41:22 -07:00
Saleem Abdulrasool
7fdfe5b88f build: use find_package(Python3) if available
This is primarily motivated by the desire to move from Python2 to
Python3.  `PYTHON_EXECUTABLE` is ambiguous.  This explicitly identifies
the python interpreter in use.  Since the LLVM build seems to be able to
completed successfully with python3, use that across the build.  The old
path aliases `PYTHON_EXECUTABLE` to be treated as Python3.
2020-04-28 09:24:27 -07:00
Craig Topper
8757f48ecf [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand().
This method has been commented as deprecated for a while. Remove
it and replace all uses with the equivalent getCalledOperand().

I also made a few cleanups in here. For example, to removes use
of getElementType on a pointer when we could just use getFunctionType
from the call.

Differential Revision: https://reviews.llvm.org/D78882
2020-04-27 22:17:03 -07:00
Saleem Abdulrasool
e3224a705b Revert "build: use find_package(Python3) if available"
This reverts commit cd84bfb8142bc7ff3a07a188ffb809f1d86d1fd7.  Although
this passed the CI in phabricator, some of the bots are missing python3
packages, revert it temporarily.
2020-04-27 20:03:32 -07:00
Saleem Abdulrasool
1e606319f4 build: use find_package(Python3) if available
This is primarily motivated by the desire to move from Python2 to
Python3.  `PYTHON_EXECUTABLE` is ambiguous.  This explicitly identifies
the python interpreter in use.  Since the LLVM build seems to be able to
completed successfully with python3, use that across the build.  The old
path aliases `PYTHON_EXECUTABLE` to be treated as Python3.
2020-04-28 01:33:10 +00:00
Alexander Shaposhnikov
0216622484 [llvm-objcopy][MachO] Fix build
Some compilers are confused when the same name is used in different contexts.
Rename the field Section to unbreak the build.
(Caught by the buildbot http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/22374)
2020-04-27 18:20:01 -07:00
Alexander Shaposhnikov
6e8de6d572 [llvm-objcopy][MachO] Handle relocation entries where r_extern is zero
Fix handling of relocations with r_extern == 0.
If r_extern == 0 then r_symbolnum is an index of a section rather than a symbol index.

Patch by Seiya Nuta and Alexander Shaposhnikov.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78946
2020-04-27 17:59:07 -07:00
Fangrui Song
079c4bf20e [llvm-objcopy] Don't specialize the all zero p_paddr case
Spotted by https://reviews.llvm.org/D74755#1998673

> it looks like OrderedSegments in the function is only used to set the physical address to the virtual address when there are no physical addresses set amongst these sections.

I believe this behavior was copied from https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6ffd79000b45e77b3625143932ffbf781b6aecab (2008-05)
The commit was made for some corner cases of very old linkers.
This special rule does not seem useful and remove it can allow us to
delete a large chunk of code.

Reviewed By: jhenderson, jakehehrlich

Differential Revision: https://reviews.llvm.org/D78786
2020-04-27 11:20:41 -07:00
Fangrui Song
d163afe84b [llvm-objdump] Print target address with evaluateMemoryOperandAddress()
D63847 added `MCInstrAnalysis::evaluateMemoryOperandAddress()`. This patch
leverages the feature to print the target addresses for evaluable instructions.

```
-400a: movl 4080(%rip), %eax
+400a: movl 4080(%rip), %eax  # 5000 <data1>
```

This patch also deletes `MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || MIA->isConditionalBranch(Inst)`
which is used to guard `MCInstrAnalysis::evaluateBranch()`

Reviewed By: jhenderson, skan

Differential Revision: https://reviews.llvm.org/D78776
2020-04-27 09:43:51 -07:00
Simon Pilgrim
0c47936cc3 [opt] PassPrinters.h - remove unused includes + forward declarations. NFC. 2020-04-27 13:51:31 +01:00
Simon Pilgrim
87ecb5e4b2 [opt] NewPMDriver.h - remove unused LLVMContext forward declaration. NFC. 2020-04-27 13:51:31 +01:00
Alexander Shaposhnikov
e118dc8b0c [llvm-objcopy][MachO] Fix segment's vmsize
This diff fixes the calculation of the field vmsize
in LC_SEGMENT/LC_SEGMENT_64 load commands.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78799
2020-04-26 20:41:49 -07:00