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

12031 Commits

Author SHA1 Message Date
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
Igor Kudrin
904fe61e2d [llvm-dwp] Refuse DWARFv5 input DWP files.
The library can parse DWARFv5 unit index sections of DWP files, but
llvm-dwp is not ready to process them. Refuse such input files for now.

Differential Revision: https://reviews.llvm.org/D77143
2020-04-25 18:59:41 +07:00
Fangrui Song
47a31a63f5 [XRay] Change Sled.Function to PC-relative for sled version 2 and make llvm-xray support sled version 2 addresses
Follow-up of D78082 and D78590.

Otherwise, because xray_instr_map is now read-only, the absolute
relocation used for Sled.Function will cause a text relocation.
2020-04-24 14:41:56 -07:00
Fangrui Song
155fe2e371 [gold] Simplify with StringRef::consume_front. NFC
Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D78819
2020-04-24 12:39:35 -07:00
Alexandre Ganea
27cd40a456 [llvm-cov] Prevent llvm-cov from using too many threads
As reported here: https://reviews.llvm.org/D75153#1987272

Before, each instance of llvm-cov was creating one thread per hardware core, which wasn't needed probably because the number of inputs were small. This was probably causing a thread rlimit issue on large core count systems.

After this patch, the previous behavior is restored (to what was before rG8404aeb5):

If --num-threads is not specified, we create one thread per input, up to num.cores.
When specified, --num-threads indicates any number of threads, with no upper limit.

Differential Revision: https://reviews.llvm.org/D78408
2020-04-24 15:28:25 -04:00
serge-sans-paille
69169b30b2 Update compiler extension integration into the build system
The approach here is to create a new (empty) component, `Extensions', where all
statically compiled extensions dynamically register their dependencies. That way
we're more natively compatible with LLVMBuild and llvm-config.

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

Differential Revision: https://reviews.llvm.org/D78192
2020-04-24 09:40:14 +02:00
Hubert Tong
3c957e42f4 [llvm-objdump][ELF][NFC] Create ELFDump.h
Summary:
Continuing from D77285, the external interfaces implemented by
`ELFDump.cpp` are now declared in `ELFDump.h` and moved into the
`llvm::objdump` namespace. Externs defined in `ELFDump.cpp` that are
unreferenced externally are also made static.

Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty

Reviewed By: jhenderson, MaskRay

Subscribers: RKSimon, rupprecht, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78695
2020-04-23 21:24:37 -04:00
Alexander Shaposhnikov
22888ebe65 [llvm-objcopy][MachO] Copy LC_LOAD_WEAK_DYLIB load commands
LC_LOAD_WEAK_DYLIB is analogous to LC_LOAD_DYLIB and doesn't require any special handling.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78602
2020-04-23 12:21:44 -07:00
Mircea Trofin
196afafb83 [llvm][NFC][CallSite] Removed CallSite from few implementation details
Reviewers: dblaikie, craig.topper

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78724
2020-04-23 10:36:36 -07:00
Alexander Shaposhnikov
aede5a0e78 [llvm-objcopy][MachO] Add missing license header
Add missing license header to Object.cpp.
NFC.
2020-04-22 16:07:40 -07:00
Alexander Shaposhnikov
1827f4c151 [llvm-objcopy][MachO] Fix n_sect field
This tiny change is a follow-up to the previous commit f34fdbcf996a
where the update of n_sect was missing.

Test plan: make check-all
2020-04-22 15:44:03 -07:00
Alexander Shaposhnikov
3158d1df4d [llvm-objcopy][MachO] Make --remove-section clean up dead symbols
Make --remove-section clean up dead symbols, return an Error if it can't be safely done.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78474
2020-04-22 14:26:42 -07:00
Alexander Shaposhnikov
b5506fb989 [ObjectYAML][MachO] Add support for relocations
Add support for relocations for MachO to ObjectYAML / yaml2obj / obj2yaml.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D77844
2020-04-22 11:50:55 -07:00
Christopher Tetreault
7f0438624e [SVE] Add new VectorType subclasses
Summary:
Introduce new types for fixed width and scalable vectors.

Does not remove getNumElements yet so as to not break code during transition
period.

Reviewers: deadalnix, efriedma, sdesmalen, craig.topper, huntergr

Reviewed By: sdesmalen

Subscribers: jholewinski, arsenm, jvesely, nhaehnle, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, kerbowa, Joonsoo, grosul1, frgossen, lldb-commits, tschuett, hiraditya, rkruppe, psnobl, llvm-commits

Tags: #llvm, #lldb

Differential Revision: https://reviews.llvm.org/D77587
2020-04-22 08:59:01 -07:00
jasonliu
d6af2bbecf [llvm-objdump][XCOFF] Print more symbol info in relocation
Summary:
Print more symbol info in relocation printing when
--symbol-description is specified.

Differential Revision: https://reviews.llvm.org/D78499
2020-04-22 13:52:08 +00:00
James Henderson
f9eb5e8f70 [llvm-objdump] Look in all viable sections for call/branch targets
Prior to this patch, llvm-objdump would only look in the last section
(according to the section header table order) that matched an address
for a symbol when identifying the target symbol of a call or branch
operation. If there are multiple sections with the same address, due to
some of them being empty, it did not look in those, even if the symbol
couldn't be found in the first section looked in.

This patch causes llvm-objdump to look in all sections for possible
candidate symbols. If there are multiple possible symbols, it picks one
from a non-empty section, if possible (as that is more likely to be the
"real" symbol since functions can't really be in emptiy sections),
before falling back to those in empty sections. If all else fails, it
falls back to absolute symbols as it did before.

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

Reviewed by: grimar, Higuoxing
2020-04-22 12:28:30 +01:00
Georgii Rymar
c57ab2a547 [obj2yaml] - Fix the issue with dumping empty sections when dumping program headers.
Imagine we have:

```
ProgramHeaders:
  - Type:  PT_LOAD
    Flags: [ PF_W, PF_R ]
    Sections:
      - Section: .bar
    VAddr: 0x2000
Sections:
  - Name:    .foo
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
    Address: 0x1000
  - Name:    .bar
    Type:    SHT_PROGBITS
    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
    Address: 0x2000
```

Both `.foo` and `.bar` share the same starting file offset,
but `VA(.foo)` < `VA(PT_LOAD)`, we should not include it into segment.

This patch fixes the issue.

Differential revision: https://reviews.llvm.org/D77652
2020-04-22 12:36:00 +03:00
Fangrui Song
1148aba0c6 Reland D76675 [llvm-objcopy] Match GNU behaviour regarding file symbols
Don't error on Config.KeepFileSymbols for COFF and Mach-O.

Original description:

GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: https://github.com/android/ndk/issues/1212

Differential Revision: https://reviews.llvm.org/D76675
2020-04-20 21:18:48 -07:00
Yi Kong
920851081d Revert "[llvm-objcopy] Match GNU behaviour regarding file symbols"
This reverts commit 7c65e88d0bc85ff2732a4e23c397ff842b97b828.

Broke non ELF targets.
2020-04-21 12:04:01 +08:00
Yi Kong
1e469f4962 [llvm-objcopy] Match GNU behaviour regarding file symbols
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: https://github.com/android/ndk/issues/1212

Differential Revision: https://reviews.llvm.org/D76675
2020-04-21 11:30:04 +08:00
Alexander Shaposhnikov
71a88d00fa [llvm-objcopy][MachO] Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands
Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78339
2020-04-20 16:34:46 -07:00
Georgii Rymar
d3ebe0593f [obj2yaml] - Teach obj2yaml to dump SHT_NOBITS sections when dumping program headers.
SHT_NOBITS are a bit special because occupy no physical space.
This patch adds support for them.

Differential revision: https://reviews.llvm.org/D77805
2020-04-20 14:35:28 +03:00
Georgii Rymar
f462f0718a [llvm-readobj] - Fix crashes and misbehaviors when reading strings from broken string tables.
There are cases when we either might print garbage or crash when
reading strings for dumping dynamic tags.

For example when a string table is not null-terminated or goes past the EOF.
This patch fixes issues mentioned.

Differential revision: https://reviews.llvm.org/D77216
2020-04-20 14:14:17 +03:00
David Blaikie
0118194836 llvm-dwarfdump: Fix UB (unsequenced writes) introduced in e0fd87cc64d5
Unsequenced write due to "x &= f()" where 'f()' modifies 'x'.

Detected by the llvm-clang-x86_64-expensive-checks-win buildbot.
Investigated/identified by Galina - thanks!
2020-04-19 21:35:04 -07:00
Markus Böck
ababa31040 [llvm-objdump] Demangle C++ Symbols in branch and call targets
Currently C++ symbols are demangled in the symbol table as well as in
the disassembly and relocations. This patch adds demangling of C++
symbols in targets of calls and branches making it easier to decipher
control flow in disassembly. This also matches up with GNUobjdump's
behavior

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D77957
2020-04-18 08:30:50 -07:00
vgxbj
bbdc25ab11 [Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> getSymbolFlags().
This change enables getSymbolFlags() to return errors which benefit error reporting in clients.

Differential Revision: https://reviews.llvm.org/D77860
2020-04-18 21:27:57 +08:00
Lang Hames
4861433a3c [llvm-objcopy][MachO] Correctly identify object file endianness.
The header magic value is held in the native endianness, so the method used in
cc0ec3fdb9d. Use MachOReader / MachOWriter's existing endianness tests instead.
2020-04-16 21:54:01 -07:00
Lang Hames
7e5e5ed624 [llvm-objcopy][MachO] Fix MachO::relocation_info use after 386f1c114d5.
Use shift/mask operations to access r_symbolnum rather than relying on
MachO::relocation_info. This should fix the big-endian bot failures that were
caused by 386f1c114d5.
2020-04-16 18:26:59 -07:00
Wouter van Oortmerssen
2d2a0b49b2 [WebAssembly] Add int32 DW_OP_WASM_location variant
This to allow us to add reloctable global indices as a symbol.
Also adds R_WASM_GLOBAL_INDEX_I32 relocation type to support it.

See discussion in https://github.com/WebAssembly/debugging/issues/12
2020-04-16 16:32:17 -07:00
Richard Smith
be765b5d17 llvm-addr2line: assume addresses on the command line are hexadecimal rather than attempting to guess the base based on the form of the number.
Summary:
This matches the behavior of GNU addr2line. We previously treated
hexadecimal addresses as binary if they started with 0b, otherwise as
octal if they started with 0, otherwise as decimal.

This only affects llvm-addr2line; the behavior of llvm-symbolize is
unaffected.

Reviewers: ikudrin, rupprecht, jhenderson

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73306
2020-04-16 16:16:21 -07:00
Mircea Trofin
2c2f3008dd [llvm][NFC][CallSite] Removed CallSite from some implementation details.
Reviewers: craig.topper, dblaikie

Subscribers: hiraditya, jfb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78256
2020-04-15 22:27:05 -07:00
Teresa Johnson
ca9019a39c Allow disabling of vectorization using internal options
Summary:
Currently, the internal options -vectorize-loops, -vectorize-slp, and
-interleave-loops do not have much practical effect. This is because
they are used to initialize the corresponding flags in the pass
managers, and those flags are then unconditionally overwritten when
compiling via clang or via LTO from the linkers. The only exception was
-vectorize-loops via opt because of some special hackery there.

While vectorization could still be disabled when compiling via clang,
using -fno-[slp-]vectorize, this meant that there was no way to disable
it when compiling in LTO mode via the linkers. This only affected
ThinLTO, since for regular LTO vectorization is done during the compile
step for scalability reasons. For ThinLTO it is invoked in the LTO
backends. See also the discussion on PR45434.

This patch makes it so the internal options can actually be used to
disable these optimizations. Ultimately, the best long term solution is
to mark the loops with metadata (similar to the approach used to fix
-fno-unroll-loops in D77058), but this enables a shorter term
workaround, and actually makes these internal options useful.

I constant propagated the initial values of these internal flags into
the pass manager flags (for some reasons vectorize-loops and
interleave-loops were initialized to true, while vectorize-slp was
initialized to false). As mentioned above, they are overwritten
unconditionally so this doesn't have any real impact, and these initial
values aren't particularly meaningful.

I then changed the passes to check the internl values and return without
performing the associated optimization when false (I changed the default
of -vectorize-slp to true so the options behave similarly). I was able
to remove the hackery in opt used to get -vectorize-loops=false to work,
as well as a special option there used to disable SLP vectorization.

Finally, I changed thinlto-slp-vectorize-pm.c to:
a) Only test SLP (moved the loop vectorization checking to a new test).
b) Use code that is slp vectorized when it is enabled, and check that
instead of whether the pass is enabled.
c) Test the new behavior of -vectorize-slp.
d) Test both pass managers.

The loop vectorization (and associated interleaving) testing I moved to
a new thinlto-loop-vectorize-pm.c test, with several changes:
a) Changed the flags on the interleaving testing so that it will
actually interleave, and check that.
b) Test the new behavior of -vectorize-loops and -interleave-loops.
c) Test both pass managers.

Reviewers: fhahn, wmi

Subscribers: hiraditya, steven_wu, dexonsmith, cfe-commits, davezarzycki, llvm-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77989
2020-04-14 18:09:10 -07:00
Hubert Tong
41f2e52f97 [llvm-objdump][Wasm][NFC] Create WasmDump.h
Summary:
Continuing from D77285, the external interfaces implemented by
`WasmDump.cpp` are now declared in `WasmDump.h` and moved into the
`llvm::objdump` namespace.

Reviewers: jhenderson, MaskRay, DiggerLin, jasonliu, daltenty

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D77990
2020-04-14 18:26:24 -04:00
Eli Friedman
82b54aea79 Enable new passmanager plugin support for LTO.
This should make both static and dynamic NewPM plugins work with LTO.
And as a bonus, it makes static linking of OldPM plugins more reliable
for plugins with both an OldPM and NewPM interface.

I only implemented the command-line flag to specify NewPM plugins in
llvm-lto2, to show it works. Support can be added for other tools later.

Differential Revision: https://reviews.llvm.org/D76866
2020-04-14 15:07:07 -07:00
David Blaikie
1519ccfd27 Reapply "llvm-dwarfdump: Report errors when failing to parse loclist/debug_loc entries""
Originally committed as 416fa7720e30750939c53935051c6c750dfad2c2
Reverted (due to buildbot failure - breaking lldb) in 7a45aeacf3a23449039ef2efcf476995ae1c7007.

I still can't seem to build lldb locally, but Pavel Labath has kindly
provided a potential fix to preserve the old behavior in lldb by
registering a simple recoverable error handler there that prints to the
desired stream in lldb, rather than stderr.
2020-04-14 14:44:32 -07:00
Georgii Rymar
180c8196c1 [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.
It can be used to avoid passing the begin and end of a range.
This makes the code shorter and it is consistent with another
wrappers we already have.

Differential revision: https://reviews.llvm.org/D78016
2020-04-14 14:11:02 +03:00
Eli Friedman
7ea99307e1 Make IRBuilder automatically set alignment on load/store/alloca.
This is equivalent in terms of LLVM IR semantics, but we want to
transition away from using MaybeAlign to represent the alignment of
these instructions.

Differential Revision: https://reviews.llvm.org/D77984
2020-04-13 13:43:14 -07:00
jasonliu
24b44296ab [llvm-objdump] Fix incomplete relocation output for -D -r mode
This patch intends to fix incomplete relocation printing for
XCOFF (potentially for other targets).

Differential Revision: https://reviews.llvm.org/D77580
2020-04-13 15:51:36 +00:00
David Blaikie
356c6ad409 Revert "llvm-dwarfdump: Report errors when failing to parse loclist/debug_loc entries"
Broke an LLDB build bot & I can't seem to build LLDB locally to fix
forward...
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/15567/steps/test/logs/stdio

This reverts commit 416fa7720e30750939c53935051c6c750dfad2c2.
2020-04-11 16:54:49 -07:00
Benjamin Kramer
d4c4773e87 Simplify string joins. NFCI. 2020-04-11 17:20:11 +02:00
David Blaikie
f04e26215b llvm-dwarfdump: Report errors when failing to parse loclist/debug_loc entries
This probably isn't ideal - the error was being printed specifically
inline with the dumping that was more legible - but then the error
wasn't reported to stderr and didn't produce a non-zero exit code.

Probably the error message could be improved by adding more context now
that it isn't printed in-situ of the DIE dumping as much.
2020-04-10 17:28:09 -07:00
Daniel Sanders
f1646cbf11 Make TargetPassConfig and llc add pre/post passes the same way. NFC
Summary:
At the moment, any changes we make to the passes that can be
injected before/after others (e.g. -verify-machineinstrs and
-print-after-all) have to be duplicated in both
TargetPassConfig (for normal execution, -start-before/
-stop-before/etc) and llc (for -run-pass). Unify this pass
injection into addMachinePrePass/addMachinePostPass that both
TargetPassConfig and llc can use.

Reviewers: vsk, aprantl, bogner

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77887
2020-04-10 13:46:53 -07:00
Fangrui Song
c96a431cd3 [llvm-dwarfdump] Interface cleanup. NFC
This patch moves interface declarations into llvm-dwarfdump.h and wrap
declarations in anonymous namespaces as appropriate. At the same time,
the externals are moved into the `llvm::dwarfdump` namespace`.

Reviewed By: djtodoro

Differential Revision: https://reviews.llvm.org/D77848
2020-04-10 09:22:56 -07:00
David Blaikie
4f1d6dd171 llvm-dwarfdump: Return non-zero on error
Makes it easier to test "this doesn't produce an error" (& indeed makes
that the implied default so we don't accidentally write tests that have
silent/sneaky errors as well as the positive behavior we're testing for)

Though the support for applying relocations is patchy enough that a
bunch of tests treat lack of relocation application as more of a warning
than an error - so rather than me trying to figure out how to add
support for a bunch of relocation types, let's degrade that to a warning
to match the usage (& indeed, it's sort of more of a tool warning anyway
- it's not that the DWARF is wrong, just that the tool can't fully cope
with it - and it's not like the tool won't dump the DWARF, it just won't
follow/render certain relocations - I guess in the most general case it
might try to render an unrelocated value & instead render something
bogus... but mostly seems to be about interesting relocations used in
eh_frame (& honestly it might be nice if we were lazier about doing this
relocation resolution anyway - if you're not dumping eh_frame, should we
really be erroring about the relocations in it?))
2020-04-09 20:53:58 -07:00
Hubert Tong
ea5be969d3 [llvm-objdump][NFC] MachODump.cpp interface cleanup
Continuing from D77388, this patch moves interface declarations
associated with `MachODump.cpp` into the headers corresponding to the
file that defines the variable. At the same time, these externs are
moved into the `llvm::objdump` namespace. The externs defined in
`MachODump.cpp` that are not referenced outside of it are given internal
linkage.

This patch does not rename the external functions defined by
`MachODump.cpp` that are not clearly named as being specific to Mach-O.

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D77730
2020-04-09 15:35:33 -04:00
Eric Schweitz
9247ec34a6 [Flang] add flang as a new subproject in cmake
Summary: This patch is some minor prep work for merging the flang(f18) project into the monorepo.  This patch adds "flang" as a supported target for the LLVM_ENABLE_PROJECTS option.

Reviewers: fhahn, tstellar, jdoerfert, beanz, DavidTruby

Reviewed By: DavidTruby

Subscribers: hfinkel, DavidTruby, aartbik, mgorny, llvm-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D72416
2020-04-09 16:13:18 +01:00
Georgii Rymar
4f145003ad [obj2yaml] - Do not dump the segment's "Align" field when it is equal to 1.
yaml2obj sets the `Align` to 1 by default, hence we can stop
dumping it to reduce the output.

Differential revision: https://reviews.llvm.org/D77716
2020-04-09 14:20:36 +03:00
Clement Courbet
19cd036484 [llvm-exegesis] Fix build with !HAS_LIBPFM.
Fixes 9fb871866e2b.
2020-04-08 16:02:11 +02:00
Alexey Lapshin
1ce931d8ef [DWARFLinker][dsymutil] followup for 88c2137b6d49f88186d0957a4e2d8030a3967334
That patch is a followup for "Move DwarfStreamer into DWARFLinker".
It fixes build with LLVM_LINK_LLVM_DYLIB.
2020-04-08 16:46:52 +03:00
Clement Courbet
1f97534ae0 [llvm-exegesis][NFC] Let the pfm::Counter own the PerfHelper.
A perf helper is always only ever cretaed to be checked for validity
then passed as Counter ctor argument, never to be touched again.
Its lifetime should outlive that of the counter, and there is never any
reason to have two different counters of top of the perf helper.
Make sure these assumptions always hold by making the Counter consume the
PerfHelper.
2020-04-08 15:37:30 +02:00
Clement Courbet
1cb40bb793 [llvm-exegesis][NFC] Remove dead code. 2020-04-08 14:29:26 +02:00
James Henderson
ec45a0d60a [llvm-objdump] Fix unstable disassembly output for sections with same address
When two sections shared the same address, the disassembly code was
using pointer values when sorting (see the SectionRef less than
operator). Since those values aren't guaranteed to have a specific
order, this meant the disassembly code would sometimes change which
section to pick when finding symbols targeted by calls in fully linked
objects.

This change fixes the non-determinism, so that the same section is
always picked. This might have a negative impact in that now a section
without any symbol might be picked over a section with symbols, but this
will be addressed in a later commit.

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

Reviewed by: grimar, MaskRay

Differential Revision: https://reviews.llvm.org/D77640
2020-04-08 10:57:12 +01:00
Fangrui Song
d41ca54775 [ThinLTO] Drop dso_local if a GlobalVariable satisfies isDeclarationForLinker()
dso_local leads to direct access even if the definition is not within this compilation unit (it is
still in the same linkage unit). On ELF, such a relocation (e.g. R_X86_64_PC32) referencing a
STB_GLOBAL STV_DEFAULT object can cause a linker error in a -shared link.

If the linkage is changed to available_externally, the dso_local flag should be dropped, so that no
direct access will be generated.

The current behavior is benign, because -fpic does not assume dso_local
(clang/lib/CodeGen/CodeGenModule.cpp:shouldAssumeDSOLocal).
If we do that for -fno-semantic-interposition (D73865), there will be an
R_X86_64_PC32 linker error without this patch.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D74751
2020-04-07 15:46:01 -07:00
Wei Mi
0ca1ed2836 Recommit [SampleFDO] Add flag for partial profile.
Fix the error of show-prof-info.test on some platforms without zlib.

The common profile usage is to collect profile from a target and then use the profile to guide the optimized build for the same target. There are some cases that no profile can be collected for a target. In those cases, although no full profile is available, it is possible to have some partial profile collected from other targets to optimize common libraries and utilities. A flag is needed to tell the partial profile from the full profile apart, so compiler can use different strategy for them.

Differential Revision: https://reviews.llvm.org/D77426
2020-04-07 14:28:25 -07:00
Wei Mi
11ae325c37 Revert "[SampleFDO] Add flag for partial profile." show-prof-info.test breaks on some platforms.
This reverts commit e3ba652a1440794eff0b43ce747f1b0488585d22.
2020-04-07 12:54:51 -07:00
Wei Mi
eb03930b3a [SampleFDO] Add flag for partial profile.
The common profile usage is to collect profile from a target and then use the profile to guide the optimized build for the same target. There are some cases that no profile can be collected for a target. In those cases, although no full profile is available, it is possible to have some partial profile collected from other targets to optimize common libraries and utilities. A flag is needed to tell the partial profile from the full profile apart, so compiler can use different strategy for them.

Differential Revision: https://reviews.llvm.org/D77426
2020-04-07 12:17:56 -07:00
Alexey Lapshin
6e415ad8d8 [DWARFLinker][dsymutil][NFC] Move DwarfStreamer into DWARFLinker.
For implementing "remove obsolete debug info in lld", it is neccesary
to have DWARF generation code implementation. dsymutil uses DwarfStreamer
for that purpose. DwarfStreamer uses AsmPrinter. It is considered OK
to use AsmPrinter based code in lld(D74169). This patch moves
DwarfStreamer implementation into DWARFLinker, so that it could be reused
from lld.

Generally, a better place for such a common DWARF generation code would be
not DWARFLinker but an additional separate library. Such a library could
contain a single version of DWARF generation routines and could also
be independent of AsmPrinter. At the current moment, DwarfStreamer
does not pretend to be such a general implementation of DWARF generation.
So I decided to put it into DWARFLinker since it is the only user
of DwarfStreamer.

Testing: it passes "check-all" lit testing. MD5 checksum for clang .dSYM
bundle matches for the dsymutil with/without that patch.

Reviewed By: JDevlieghere

Differential revision: https://reviews.llvm.org/D77169
2020-04-07 21:21:54 +03:00
Aaron Ballman
70eff8376e Check LLVM_BUILD_LLVM_C_DYLIB before building the C DLL with MSVC. 2020-04-07 13:13:58 -04:00
diggerlin
a53a69c279 [NFC][XCOFF] refactor readobj/XCOFFDumper.cpp
SUMMARY:

refactor readobj/XCOFFDumper.cpp with helper function getAlignmentLog2() , getSymbolType(), isLabel().

Reviewers: Hubert Tong, James Henderson
Subscribers: rupprecht, seiyai,hiradityu

Differential Revision: https://reviews.llvm.org/D77562
2020-04-07 11:33:31 -04:00
Georgii Rymar
4978c63e88 [llvm-readobj] - Introduce warnings for cases when unable to read strings from string tables.
Currently we have no dedicated warnings, but we return error message instead of a result.
It is generally not consistent with another warnings we have.

This change was suggested and discussed here:
https://reviews.llvm.org/D77216#1954873

This change refines error messages we report and also I had to update the API
to implement it.

Differential revision: https://reviews.llvm.org/D77399
2020-04-07 14:40:32 +03:00