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

12070 Commits

Author SHA1 Message Date
Sameer Arora
6bd4cdd3c7 [llvm-libtool-darwin] Support universal outputs
Add support for producing universal binaries containing archives when
`llvm-libtool-darwin` is given inputs of multiple architectures.

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D85334
2020-08-14 11:32:07 -07:00
Lang Hames
35f432b49e Re-apply "[llvm-jitlink] Don't demote unreferenced definitions in -harness mode"
This reapplies commit e137b550587a85b0d9c9c539edc79de0122b6946 with
fixes for the broken test case: Non-global symbols should only be
skipped after checking that they're not referenced by the harness.
2020-08-13 13:23:17 -07:00
Haowei Wu
d8abdb26ca [elfabi] Move llvm-elfabi related code to InterfaceStub library
This change moves elfabi related code to llvm/InterfaceStub library
so it can be shared by multiple llvm tools without causing cyclic
dependencies.

Differential Revision: https://reviews.llvm.org/D85678
2020-08-13 11:51:44 -07:00
Lang Hames
82307c21a7 Revert "[llvm-jitlink] Don't demote unreferenced definitions in -harness mode."
This reverts commit e137b550587a85b0d9c9c539edc79de0122b6946.

This commit broke a test case. Reverting while I investigate.
2020-08-13 11:45:24 -07:00
Lang Hames
dba439b591 [llvm-jitlink] Don't demote unreferenced definitions in -harness mode.
Demoting unreferenced externals is unsafe if multiple interdependent test
objects are used, including objects loaded from archives.
2020-08-13 11:19:35 -07:00
Sameer Arora
7aa42c2f0c [llvm-libtool-darwin] Add support for -arch_only
Add support for -arch_only option for llvm-libtool-darwin. This diff
also adds support for accepting universal files as input and flattening
them to create the required static library. Supports input universal
files contaning both Mach-O object files or archives.

Differences from cctools' libtool:
- `-arch_only` can be specified multiple times
- archives containing universal files are considered invalid (libtool
allows such archives)

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D84770
2020-08-13 11:08:46 -07:00
Fangrui Song
311d485856 [llvm-objdump] Change symbol name/PLT decoding errors to warnings
If the referenced symbol of a J[U]MP_SLOT is invalid (e.g. symbol index 0), llvm-objdump -d will bail out:

```
error: 'a': st_name (0x326600) is past the end of the string table of size 0x7
```

where 0x326600 is the st_name field of the first entry past the end of .symtab

Change it to a warning to continue dumping.
`X86/plt.test` uses a prebuilt executable, so I pick `ELF/AArch64/plt.test`
which has a YAML input and can be easily modified.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85623
2020-08-13 08:13:42 -07:00
Georgii Rymar
08bebae601 [llvm-readobj/elf] - Cleanup helpers that are used to print segment types. NFCI.
`getElfSegmentType` and `getElfPtType` are methods that are used for printing
segment types for LLVM and GNU styles accordingly.

This patch does a cleanup and simplification that allows to avoid
the code duplication and to get rid of one macro.

Differential revision: https://reviews.llvm.org/D85830
2020-08-13 14:07:29 +03:00
Georgii Rymar
8ff56b3ebf [llvm-readobj/elf][test] - Refine --headers testing and the related code comment.
Specifying --headers is equivalent to setting --file-headers,
--program-headers and --section-headers at the same time.

The existent test case uses a precompiled object and doesn't test the
output properly. This patch fixes it.

Differential revision: https://reviews.llvm.org/D85832
2020-08-13 13:52:49 +03:00
Xing GUO
b9e787ce80 [DWARFYAML] Replace InitialLength with Format and Length. NFC.
This change replaces the InitialLength of pub-tables with Format and
Length. All the InitialLength fields have been removed.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85880
2020-08-13 18:39:03 +08:00
Xing GUO
a3c52b27f2 [macho2yaml] Remove an unused variable. NFC. 2020-08-13 11:14:31 +08:00
Georgii Rymar
88b9fc954b [llvm-readobj] - Refine logic of the symbol table locating in printRelocationsHelper().
This removes the last `unwrapOrError` call from the `printRelocationsHelper`.

There is a little additional complexity because of `SHT_RELR/SHT_ANDROID_RELR` sections.
Such sections contains only relative relocations and they do not have a
symbol table associated with them, hence we should not try to treat
their `sh_link` field as a reference to a symbol table.

Differential revision: https://reviews.llvm.org/D85430
2020-08-12 14:03:56 +03:00
Jordan Rupprecht
97e61228e0 [NFC][llvm-objcopy] Fix redundant config checks.
The check for unsupported options checks some configs twice in a || expression. Fixes PR47107.
2020-08-11 10:37:19 -07:00
Lang Hames
f0d37fd69e [ORC] Move file-descriptor based raw byte channel into a public header.
This will enable re-use in other llvm tools.
2020-08-11 09:50:58 -07:00
Lang Hames
ab36f344d6 [llvm-jitlink] Fix a file comment. 2020-08-11 09:50:58 -07:00
Fangrui Song
367b809d42 [split-file] Fix sys::fs::remove() on Solaris after D83834
where stdio.h ::remove() may set errno to EEXIST instead of ENOTEMPTY.

POSIX.1-2017 allows EEXIST for unlink() (which is called by remove()):

> [EEXIST] or [ENOTEMPTY]
> The flag parameter has the AT_REMOVEDIR bit set and the path argument names a directory that is not an empty directory, or there are hard links to the directory other than dot or a single entry in dot-dot.

Reviewed By: ro

Differential Revision: https://reviews.llvm.org/D85690
2020-08-11 08:05:10 -07:00
Georgii Rymar
9d31094c7b [llvm-readobj/elf] - Remove unwrapOrError calls from DumpStyle<ELFT>::printRelocationsHelper.
It removes all `unwrapOrError` calls except the first one, which
is is bit different and can be removed separately.

Differential revision: https://reviews.llvm.org/D85303
2020-08-11 16:49:37 +03:00
Haowei Wu
f44281335e Revert "Move ELFObjHandler to TextAPI library"
This reverts commit e6f8ba12e6ea97cbf4374b70e78309c2d859ca1c due
to build failures.
2020-08-10 21:31:29 -07:00
Haowei Wu
1fa1012fcc Move ELFObjHandler to TextAPI library
This change moves ELFObjHandler to llvm/TextAPI library so it can
be used by different llvm tools.
2020-08-10 21:23:39 -07:00
Xing GUO
99ed94570d [macho2yaml] Refactor the DWARF section dumpers.
This patch refactors the DWARF section dumpers. When dumping a DWARF
section, if the DWARF parser fails to parse the section, we will dump it
as a raw content section. This patch also fixes a bug in
DWARFYAML::Data::isEmpty(). Finally, a test case that tests dumping the
__debug_aranges section is added.

Reviewed By: jhenderson, grimar

Differential Revision: https://reviews.llvm.org/D85506
2020-08-11 10:18:34 +08:00
Lang Hames
ce159bf33c [llvm-jitlink] Update llvm-jitlink to use TargetProcessControl. 2020-08-10 17:19:48 -07:00
Fangrui Song
d551fbf23e [llvm-symbolizer] Add back --version and add a -v alias
The switch from llvm::cl to OptTable (D83530) dropped --version, which
is needed by some users.

This patch also adds a -v alias, which is available in GNU addr2line.

The version dumping is similar to llvm-objcopy --version (exotic):

```
llvm-symbolizer
LLVM (http://llvm.org/):
  LLVM version 12.0.0git
  Optimized build with assertions.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake-avx512
```

Reviewed By: dyung, jhenderson

Differential Revision: https://reviews.llvm.org/D85624
2020-08-10 08:21:43 -07:00
James Henderson
73d127e3f5 [DebugInfo] Don't error for zero-length arange entries
Although the DWARF specification states that .debug_aranges entries
can't have length zero, these can occur in the wild. There's no
particular reason to enforce this part of the spec, since functionally
they have no impact. The patch removes the error and introduces a new
warning for premature terminator entries which does not stop parsing.

This is a relanding of cb3a598c87db, adding the missing obj2yaml part
that was needed.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46805. See also
https://reviews.llvm.org/D71932 which originally introduced the error.

Reviewed by: ikudrin, dblaikie, Higuoxing

Differential Revision: https://reviews.llvm.org/D85313
2020-08-10 14:57:52 +01:00
Georgii Rymar
54d50f63c3 [llvm-readelf/obj] - Refine the implementation of printMipsReginfo().
It adds the proper warnings reporting and updates the mips-reginfo.test to
remove using of the precompiled binary.

Differential revision: https://reviews.llvm.org/D85511
2020-08-09 11:10:12 +03:00
weihe
68e894ab3c [llvm-profdata] Implement llvm-profdata overlap for sample profiles
Implemented the `llvm-profdata overlap` feature for sample profiles. It reports weighted //similarity// and unweighted //overlap// metrics at program and function level for two input profiles. Similarity metrics are symmetric with regards to the order of two input profiles. By default, the tool only reports program-level summary. Users can look into function-level details via additional options `--function`, `--similarity-cutoff`, and `--value-cutoff`.

The similarity metrics are designed as follows:
* Program-level summary
    * Whole program profile similarity is an aggregate over function-level similarity `FS`: `PS = sum(FS(A) * avg_weight(A))` for all function `A`.
    * Whole program sample overlap: `PSO = common_samples / total_samples`.
    * Function overlap: `FO = #common_function / #total_function`.
    * Hot-function overlap: `HFO = #common_hot_function / #total_hot_function`.
    * Hot-block overlap: `HBO = #common_hot_block / #total_hot_block`.
* Function-level details
    * Function-level similarity is an aggregate over line/block-level similarities `BS` of all sample lines/blocks in the function, weighted by the closeness of the function's weights in two profiles: `FS = sum(BS(i)) * (1 - weight_distance(A))`.
    * Function-level sample overlap: `FSO = common_samples / total_samples` for samples in the function.

Reviewed By: wenlei, hoyFB, wmi

Differential Revision: https://reviews.llvm.org/D83852
2020-08-08 17:49:48 -07:00
Roman Lebedev
2f56715ea7 [Reduce] Rewrite function body delta pass again
It is not enough to replace all uses of users of the function with undef,
the users, we only drop instruction users, so they may stick around.

Let's try different approach - first drop bodies for all the functions
we will drop, which should take care of blockaddress issue the previous
rewrite was dealing with; then, after dropping *all* such bodies,
replace remaining uses with undef (thus all the uses are either
outside of functions, or are in kept functions)
and then finally drop functions.

This seems to work, and passes the *existing* test coverage,
but it is possible that a new issue will be discovered later :)

A new (previously crashing) test added.
2020-08-08 23:48:44 +03:00
Sameer Arora
629a98ce69 [llvm-libtool-darwin] Add support for -D and -U options
Add support for `-D` and `-U` options for llvm-libtool-darwin. `-D`
allows for using zero for timestamps and UIDs/GIDs. `-U` allows for
using actual timestamps and UIDs/GIDs.

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D84209
2020-08-07 14:44:32 -07:00
Sameer Arora
a753e1d6dd [llvm-libtool-darwin] Add support for -filelist option
Add support for `-filelist` option for llvm-libtool-darwin. `-filelist`
option allows for passing in a file containing a list of filenames.

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D84206
2020-08-07 14:29:24 -07:00
Sameer Arora
df248b9fac [llvm-libtool-darwin] Add constant CPU_SUBTYPE_ARM64_V8
Add support for constant MachO::CPU_SUBTYPE_ARM64_V8. This constant is
needed so as to match `llvm-libtool-darwin`'s behavior to that of
cctools' libtool when `-arch_only` flag is passed in on command line.

Reviewed by jhenderson, alexshap, smeenai

Differential Revision: https://reviews.llvm.org/D85041
2020-08-07 14:09:27 -07:00
Sameer Arora
a27cdf02e5 Add symlinks for libtool and install_name_tool
Add symlinks for `llvm-libtool-darwin` and
`llvm-install-name-tool`.

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D85054
2020-08-07 13:46:36 -07:00
Xing GUO
1762b5a368 [macho2yaml] Remove unused functions. NFC.
dumpDebugStrings() and dumpDebugAbbrev() are no longer used in
macho2yaml. This patch helps remove them.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D85496
2020-08-07 20:34:15 +08:00
Xing GUO
47c44c8042 [DWARFYAML][debug_info] Pull out dwarf::FormParams from DWARFYAML::Unit.
Unit.Format, Unit.Version and Unit.AddrSize are replaced with
dwarf::FormParams in D84496 to get rid of unnecessary functions
getOffsetSize() and getRefSize(). However, that change makes it
difficult to make AddrSize optional (Optional<uint8_t>). This change
pulls out dwarf::FormParams from DWARFYAML::Unit and use it as a helper
struct in DWARFYAML::emitDebugInfo().

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D85296
2020-08-06 16:39:00 +08:00
Arthur Eubanks
30eacbff3b [NewPM][opt] Add more codegen passes
Reduces number of failures by 92.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D85381
2020-08-05 18:59:52 -07:00
Stanislav Mekhanoshin
d688e1d62e [AMDGPU] gfx1031 target
Differential Revision: https://reviews.llvm.org/D85337
2020-08-05 12:36:26 -07:00
Georgii Rymar
f2d8b0a536 [llvm-readobj] - Make decode_relrs() don't return Expected<>. NFCI.
The `decode_relrs` helper is declared as:

`Expected<std::vector<Elf_Rel>> decode_relrs(Elf_Relr_Range relrs) const;`

it never returns an error though and hence can be simplified to return
a vector.

Differential revision: https://reviews.llvm.org/D85302
2020-08-05 17:05:47 +03:00
Xing GUO
7e07ca06a4 [obj2yaml] Add support for dumping the .debug_aranges section.
This patch adds support for dumping DWARF sections to obj2yaml. The
.debug_aranges section is used to illustrate the basic idea.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85094
2020-08-05 19:19:05 +08:00
Georgii Rymar
af54a4ae5b [llvm-readobj/elf] - Add a testing for --stackmap and refine the implementation.
Currently, we only test the `--stackmap` option here:
https://github.com/llvm/llvm-project/blob/master/llvm/test/Object/stackmap-dump.test
it uses a precompiled MachO binary currently and I've found no tests for this option for ELF.

The implementation also has issues. For example, it might assert on a wrong version
of the .llvm-stackmaps section. Or it might crash on an empty or truncated section.

This patch introduces a new tools/llvm-readobj/ELF test file as well as implements a few
basic checks to catch simple crashes/issues

It also eliminates `unwrapOrError` calls in `printStackMap()`.

Differential revision: https://reviews.llvm.org/D85208
2020-08-05 13:09:04 +03:00
Benjamin Kramer
eacb852738 [llvm-symbolizer] Add legacy aliases -demangle=true and -demangle=false.
This is used in the wild, don't break compatibility for no good reason.
https://github.com/google/pprof/blob/master/internal/binutils/addr2liner_llvm.go
2020-08-05 12:07:46 +02:00
Martin Storsjö
b52b24c898 [llvm-rc] Allow string table values split into multiple string literals
This can practically easily be a product of combining strings with
macros in resource files.

This fixes https://github.com/mstorsjo/llvm-mingw/issues/140.

As string literals within llvm-rc are handled as StringRefs, each
referencing an uninterpreted slice of the input file, with actual
interpretation of the input string (codepage handling, unescaping etc)
done only right before writing them out to disk, it's hard to
concatenate them other than just bundling them up in a vector,
without rearchitecting a large part of llvm-rc.

This matches how the same already is supported in VersionInfoValue,
with a std::vector<IntOrString> Values.

MS rc.exe only supports concatenated string literals in version info
values (already supported), string tables (implemented in this patch)
and user data resources (easily implemented in a separate patch, but
hasn't been requested by any end user yet), while GNU windres supports
string immediates split into multiple strings anywhere (e.g. like
(100 ICON "myicon" ".ico"). Not sure if concatenation in other
statements actually is used in the wild though, in resource files
normally built by GNU windres.

Differential Revision: https://reviews.llvm.org/D85183
2020-08-05 08:59:32 +03:00
Fangrui Song
2f952ff535 [llvm-symbolizer] Add compatibility aliases for --inlining={true,false}
D83530 removed --inlining={true,false} which were used by old asan_symbolize.py script.
Add compatibility aliases so that old asan_symbolize.py and sanitizer
binaries can work with new llvm-symbolizer.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D85228
2020-08-04 11:32:05 -07:00
Fangrui Song
f6b39f50d1 [llvm-symbolizer] Switch command line parsing from llvm::cl to OptTable
for the advantage outlined by D83639 ([OptTable] Support grouped short options)

Some behavior changes:

* -i={0,false} is removed. Use --no-inlines instead.
* --demangle={0,false} is removed. Use --no-demangle instead
* -untag-addresses={0,false} is removed. Use --no-untag-addresses instead

Added a higher level API OptTable::parseArgs which handles optional
initial options populated from an environment variable, expands response
files recursively, and parses options.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D83530
2020-08-04 08:53:15 -07:00
Georgii Rymar
e5284c876c [llvm-readobj] - A third attempt to fix BB.
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/15718/steps/build%20stage%201/logs/stdio:

FAILED: /usr/bin/c++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/llvm-readobj -I/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj -Iinclude -I/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/include -march=broadwell -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3     -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o -MF tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o.d -o tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o -c /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In function ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&)’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3374:12: error: parse error in template argument list
     if (O->size < ExpectedSize)

Note: I played with godbolt.org and was able to catch the similar "error in template argument list" error when used gcc 4.9.0 with this code.
Fix: try to introduce a variable to store `O->size`, it helped to me in godbolt.
2020-08-04 12:44:26 +03:00
Georgii Rymar
e3344de9d3 [llvm-readobj] - A second attempt to fix BB.
The failure is:
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/15711/steps/build%20stage%201/logs/stdio

FAILED: /usr/bin/c++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/llvm-readobj -I/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj -Iinclude -I/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/include -march=broadwell -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3     -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o -MF tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o.d -o tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o -c /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In function ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&)’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:12: error: parse error in template argument list
     if (O->size < ExpectedSize)
            ^
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In instantiation of ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&) [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>; uint8_t = unsigned char]’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3400:30:   required from ‘void {anonymous}::ELFDumper<ELFT>::printMipsOptions() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:2878:21:   required from ‘void {anonymous}::ELFDumper<ELFT>::printArchSpecificInfo() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:6999:1:   required from here
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:5: error: ‘size’ is not a member template function
     if (O->size < ExpectedSize)
     ^
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In instantiation of ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&) [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, true>; uint8_t = unsigned char]’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3400:30:   required from ‘void {anonymous}::ELFDumper<ELFT>::printMipsOptions() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:2878:21:   required from ‘void {anonymous}::ELFDumper<ELFT>::printArchSpecificInfo() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:6999:1:   required from here
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:5: error: ‘size’ is not a member template function
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In instantiation of ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&) [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, false>; uint8_t = unsigned char]’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3400:30:   required from ‘void {anonymous}::ELFDumper<ELFT>::printMipsOptions() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, false>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:2878:21:   required from ‘void {anonymous}::ELFDumper<ELFT>::printArchSpecificInfo() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, false>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:6999:1:   required from here
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:5: error: ‘size’ is not a member template function
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In instantiation of ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&) [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, false>; uint8_t = unsigned char]’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3400:30:   required from ‘void {anonymous}::ELFDumper<ELFT>::printMipsOptions() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, false>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:2878:21:   required from ‘void {anonymous}::ELFDumper<ELFT>::printArchSpecificInfo() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)1u, false>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:6999:1:   required from here
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:5: error: ‘size’ is not a member template function
ninja: build stopped: subcommand failed.

Fix: stop using `auto` for `O` variable.
2020-08-04 12:13:43 +03:00
Georgii Rymar
3a8cf4aa8f [llvm-readobj] - An attempt to fix BB.
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/15710/steps/build%20stage%201/logs/stdio
fails with:

/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In function ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&)’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:19: error: the value of ‘ExpectedSize’ is not usable in a constant expression
     if (O->size < ExpectedSize)
                   ^
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3369:10: note: ‘size_t ExpectedSize’ is not const
   size_t ExpectedSize =
          ^
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:12: error: parse error in template argument list
     if (O->size < ExpectedSize)
            ^
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp: In instantiation of ‘llvm::Expected<const llvm::object::Elf_Mips_Options<ELFT>*> readMipsOptions(const uint8_t*, llvm::ArrayRef<unsigned char>&, bool&) [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>; uint8_t = unsigned char]’:
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3400:30:   required from ‘void {anonymous}::ELFDumper<ELFT>::printMipsOptions() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:2878:21:   required from ‘void {anonymous}::ELFDumper<ELFT>::printArchSpecificInfo() [with ELFT = llvm::object::ELFType<(llvm::support::endianness)0u, true>]’
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:6999:1:   required from here
/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp:3373:5: error: ‘size’ is not a member template function

Fix: add 2 `const` words to variables.
2020-08-04 11:56:58 +03:00
Georgii Rymar
69a27fa6a6 [llvm-readobj/readelf] - Refine the implementation of printMipsOptions().
`printMipsOptions()` and the test related has the following issues currently:

1) It does not check the value of Elf_Mips_Options<ELFT>::size field.
2) For ODK_REGINFO options it is possible to read past the end of buffer,
   because there is no check against the `sizeof(Elf_Mips_RegInfo<ELFT>)`.
3) The error about the broken size is just printed to the standard output.
4) The binary input is used for the test.
5) There is no testing for multiple options in the .MIPS.options section,
   though the code supports it.
6) Only llvm-readobj is tested, but not llvm-readelf.
7) "Unsupported MIPS options tag" message does not reveal the tag ID/name.

This patch fixes all of these points.

Differential revision: https://reviews.llvm.org/D84854
2020-08-04 11:40:02 +03:00
Georgii Rymar
16a78424ed [llvm-readobj] - Simplify findSectionByName(). NFCI.
It turns out that findSectionByName can return
const Elf_Shdr * instead of Expected<>, because its
code never returns an error currently (it reports warnings instead).

Differential revision: https://reviews.llvm.org/D85135
2020-08-04 11:13:02 +03:00
Fangrui Song
5554745259 Add test utility 'split-file'
See https://lists.llvm.org/pipermail/llvm-dev/2020-July/143373.html
"[llvm-dev] Multiple documents in one test file" for some discussions.

This patch has explored several alternatives. The current semantics are similar to
what @dblaikie proposed.
`split-file filename output` splits the input file into multiple parts separated by
regex `^(.|//)--- filename` and write each part to the file `output/filename`
(`filename` can include path separators).

Use case A (organizing input of different formats (e.g. linker
script+assembly) in one file).

```
# RUN: split-file %s %t
# RUN: llvm-mc %t/asm -o %t.o
# RUN: ld.lld -T %t/lds %t.o -o %t
This is sometimes better than the %S/Inputs/ approach because the user
can see the auxiliary files immediately and don't have to open another file.

# asm
...
# lds
...
```

Use case B (for utilities which don't have built-in input splitting
feature):

```
// RUN: split-file %s %t
// RUN: llc < %t/1.ll | FileCheck %s --check-prefix=CASE1
// RUN: llc < %t/2.ll | FileCheck %s --check-prefix=CASE2
Combing tests prudently can improve readability.
For example, when testing parsing errors if the recovery mechanism isn't possible,
grouping the tests in one file can more readily see test coverage/strategy.

//--- 1.ll
...
//--- 2.ll
...
```

Since this is a new utility, there is no git history concerns for
UpperCase variable names. I use lowerCase variable names like mlir/lld.

Reviewed By: jhenderson, lattner

Differential Revision: https://reviews.llvm.org/D83834
2020-08-03 20:42:09 -07:00
Lang Hames
ec5336f4a3 [llvm-jitlink] Add support for static archives and MachO universal archives.
Archives can now be specified as input files the same way that object
files are. Archives will always be linked after all objects (regardless
of the relative order of the inputs) but before any dynamic libraries or
process symbols.

This patch also relaxes matching for slice triples in
StaticLibraryDefinitionGenerator in order to support this feature:
Vendors need not match if the source vendor is unknown.
2020-08-03 12:58:00 -07:00
Georgii Rymar
d73aa6dbae [llvm-readobj] - Don't stop dumping when the name of a relocation section can't be read.
This removes undesired `unwrapOrError` calls from printRelocations() methods.

Differential revision: https://reviews.llvm.org/D84408
2020-08-03 14:49:09 +03:00
Georgii Rymar
9f706106c9 [llvm-readobj] - Don't call unwrapOrErr in findSectionByName.
We have a `findSectionByName` helper that tries to find a section
by it name. It is used in a few places, but never tested.

I'd like to reuse this helper for a different place.
For this, I've changed it to return Expected<> and now it
doesn't use `unwrapOrErr` anymore. It also now a member of
Dumper class and might report warnings.

Differential revision: https://reviews.llvm.org/D84651
2020-08-03 12:41:00 +03:00
Kazu Hirata
6e4cee6f1e Use llvm::is_contained where appropriate (NFC)
Use llvm::is_contained where appropriate (NFC)

Reviewed By: kazu

Differential Revision: https://reviews.llvm.org/D85083
2020-08-01 21:51:06 -07:00
Lang Hames
b014cb8f2f [llvm-jitlink] Add -phony-externals option to suppress unresolved externals.
The -phony-externals option adds a generator which explicitly defines any
otherwise unresolved externals as null. This transforms link-time
unresolved-symbol errors into potential runtime null pointer accesses
(if an unresolved external is actually accessed during execution).

This option can be useful in -harness mode to avoid having to mock a
large number of symbols that are not reachable at runtime (e.g. unused
methods referenced by a class vtable).
2020-08-01 18:33:44 -07:00
Lang Hames
f9871c7f15 [llvm-jitlink] Support promotion of ODR weak symbols in -harness mode.
This prevents weak symbols from being immediately dead-stripped when not
directly referenced from the test harneess, enabling use of weak symbols
from the code under test.
2020-08-01 18:33:44 -07:00
Sameer Arora
fccf62295c [llvm-libtool-darwin] Refactor Slice and writeUniversalBinary
Refactoring `Slice` class and function `createUniversalBinary` from
`llvm-lipo` into  MachOUniversalWriter. This refactoring is necessary so
as to use the refactored code for creating universal binaries under
llvm-libtool-darwin.

Reviewed by alexshap, smeenai

Differential Revision: https://reviews.llvm.org/D84662
2020-07-31 09:22:35 -07:00
Xing GUO
9f60593353 [DWARFYAML] Make the debug_aranges entry optional.
This patch makes the 'debug_aranges' entry optional. If the entry is
empty, yaml2obj will only emit the header for it.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D84921
2020-07-31 20:18:53 +08:00
Lang Hames
6ca1bd0130 [llvm-jitlink] Add -harness option to llvm-jitlink.
The -harness option enables new testing use-cases for llvm-jitlink. It takes a
list of objects to treat as a test harness for any regular objects passed to
llvm-jitlink.

If any files are passed using the -harness option then the following
transformations are applied to all other files:

  (1) Symbols definitions that are referenced by the harness files are promoted
      to default scope. (This enables access to statics from test harness).

  (2) Symbols definitions that clash with definitions in the harness files are
      deleted. (This enables interposition by test harness).

  (3) All other definitions in regular files are demoted to local scope.
      (This causes untested code to be dead stripped, reducing memory cost and
      eliminating spurious unresolved symbol errors from untested code).

These transformations allow the harness files to reference and interpose
symbols in the regular object files, which can be used to support execution
tests (including fuzz tests) of functions in relocatable objects produced by a
build.
2020-07-30 15:26:19 -07:00
Yuanfang Chen
150dfe6e6c [llvm-readobj] NFC. Add -help description of --hex-dump and
--string-dump
2020-07-29 19:18:01 -07:00
Arthur Eubanks
490b642e95 [opt][NewPM] Fix typo
From https://reviews.llvm.org/D84872.
2020-07-29 14:20:01 -07:00
Arthur Eubanks
ea8ba1b79f [NewPM][opt] Revert to legacy PM when any codegen passes are specified
This reduces the number of check-llvm failures by 500.

Ideally we'd have a codegen version of PassRegistry.def, or have all the
codegen passes ported and put into PassRegistry.def. But since that
doesn't exist yet, hardcode the list of codegen IR passes.

There are still codegen passes missing from this list, I'll add them
later as I stumble upon them.

Reviewed By: asbirlea, ychen

Differential Revision: https://reviews.llvm.org/D84872
2020-07-29 13:55:11 -07:00
Georgii Rymar
21d06fcc5e [llvm-readobj] - Move out the common code from printRelocations() methods.
This introduces the printRelocationsHelper() which now contains the common
code used by both GNU and LLVM output styles.

Differential revision: https://reviews.llvm.org/D83935
2020-07-29 13:52:02 +03:00
Fangrui Song
8a55d3cc1c Revert D83834 "Add test utility 'extract'"
This reverts commit d054c7ee2e9f4f98af7f22a5b00a941eb919bd59.

There are discussions about the utility name, its functionality and user interface.
Revert before we reach consensus.
2020-07-28 13:26:33 -07:00
Anirudh Prasad
937eb07610 [Support] Use InitLLVM in llvm-stress, sancov and TableGen
This patch refactors the llvm tools namely, llvm-stress and sancov,
as well as the llvm TableGen utility, to use the new InitLLVM
interface which encapsulates PrettyStackTrace.

This is from https://reviews.llvm.org/D70702, but only for LLVM.

Reviewed-by: Kai

Differential Revision: https://reviews.llvm.org/D83484
2020-07-28 07:50:45 -04:00
Mikhail Kalashnikov
b144aa73c9 [llvm-readelf] Symbol index in symbol table printing is not reset
Stop using static variables for keeping track of symbol indices.

Bugfix for: https://bugs.llvm.org/show_bug.cgi?id=46777

Differential revision: https://reviews.llvm.org/D84606
2020-07-28 13:15:53 +03:00
Georgii Rymar
c0d38d1d0b [llvm-readelf] - Do not treat SHT_ANDROID_RELR sections the same as SHT_RELR.
Currently, when dumping section headers, llvm-readelf
prints "RELR" for SHT_ANDROID_RELR/SHT_RELR sections.
The behavior was introduced in D47919 and revealed in D84330.

But "SHT_ANDROID_RELR" has a different value from "SHT_RELR".
Also, "SHT_ANDROID_REL/SHT_ANDROID_RELA" are printed as "ANDROID_REL/ANDROID_RELA",
what makes the handling of the "SHT_ANDROID_RELR" inconsistent.

This patch makes llvm-readelf to print "ANDROID_RELR" instead of "RELR".

Differential revision: https://reviews.llvm.org/D84393
2020-07-28 11:24:58 +03:00
Wei Mi
51d4708437 Supplement instr profile with sample profile.
PGO profile is usually more precise than sample profile. However, PGO profile
needs to be collected from loadtest and loadtest may not be representative
enough to the production workload. Sample profile collected from production
can be used as a supplement -- for functions cold in loadtest but warm/hot
in production, we can scale up the related function in PGO profile if the
function is warm or hot in sample profile.

The implementation contains changes in compiler side and llvm-profdata side.
Given an instr profile and a sample profile, for a function cold in PGO
profile but warm/hot in sample profile, llvm-profdata will either mark
all the counters in the profile to be -1 or scale up the max count in the
function to be above hot threshold, depending on the zero counter ratio in
the profile. The assumption is if there are too many counters being zero
in the function profile, the profile is more likely to cause harm than good,
then llvm-profdata will mark all the counters to be -1 indicating the
function is hot but the profile is unaccountable. In compiler side, if a
function profile with all -1 counters is seen, the function entry count will
be set to be above hot threshold but its internal profile will be dropped.

In the long run, it may be useful to let compiler support using PGO profile
and sample profile at the same time, but that requires more careful design
and more substantial changes to make two profiles work seamlessly. The patch
here serves as a simple intermediate solution.

Differential Revision: https://reviews.llvm.org/D81981
2020-07-27 20:17:40 -07:00
Xing GUO
9d1bb81744 [llvm-readelf] Fix emitting incorrect number of spaces in '--hex-dump'.
This patch helps teach llvm-readelf to emit a correct number spaces when
dumping in hex format.

Before this patch, when the hex data doesn't fill the 4th column, some
spaces are missing.

```
Hex dump of section '.sec':
0x00000000 00000000 00000000 00000000 00000000 ................
0x00000010 00000000 00000000 00000000 0000 ..............
```

After this patch:

```
Hex dump of section '.sec':
0x00000000 00000000 00000000 00000000 00000000 ................
0x00000010 00000000 00000000 00000000 0000     ..............
```

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D84640
2020-07-28 09:54:33 +08:00
Kazu Hirata
0d01902704 Use llvm::is_contained where appropriate (NFC)
Summary:
This patch replaces std::find with llvm::is_contained where
appropriate.

Reviewers: efriedma, nhaehnle

Reviewed By: nhaehnle

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, rogfer01, kerbowa, llvm-commits, vkmr

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84489
2020-07-27 10:20:44 -07:00
Vy Nguyen
0724050861 Reland [llvm-exegesis] Add benchmark latency option on X86 that uses LBR for more precise measurements.
Starting with Skylake, the LBR contains the precise number of cycles between the two
        consecutive branches.
        Making use of this will hopefully make the measurements more precise than the
        existing methods of using RDTSC.

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

New change: check for existence of field `cycles` in perf_branch_entry before enabling this mode.
This should prevent compilation errors when building for older kernel whose headers don't support it.
2020-07-27 12:38:05 -04:00
Roman Lebedev
aa265a31e9 [Reduce] Argument reduction: shoe-horn new function into remaining uses of old function
Much like with function reduction, there may be remaining unhandled uses
of function, in particular in blockaddress. And in constants we can't
RAUW it with undef, because undef is not a function.
Instead, let's try to pretent that in the remaining cases, the new
signature didn't change, by bitcasting it.

A new (previously crashing) test case added.
2020-07-27 15:39:03 +03:00
Roman Lebedev
49caf4bfe4 [Reduce] Function reduction: replace all users of function with undef
There may be other users of a function other than CallInsts,
but what's more important, we can't actually replace function pointer
with undef, because for constants, that would not preserve the type
and RAUW would assert.

In particular, that affects blockaddress, however it proves to be
prohibitively complex to come up with a good test involving blockaddress:
we'd need to both ensure that the function body survives until
this pass, and is not interesting in this pass.
2020-07-27 15:39:02 +03:00
Roman Lebedev
2e1aaf1aa5 [XRay] Account: recursion detection
Summary:
Recursion detection can be non-trivial. Currently, the state-of-the-art for LLVM,
as far as i'm concerned, is D72362 `[clang-tidy] misc-no-recursion: a new check`.
However, it is quite limited:
* It does very basic call-graph based analysis, in the sense it will report even dynamically-unreachable recursion.
* It is inherently limited to a single TU
* It is hard to gauge how problematic each recursion is in practice.

Some of that can be addressed by adding clang analyzer-based check,
then it would at least support multiple TU's.

However, we can approach this problem from another angle - dynamic run-time analysis.
We already have means to capture a run-time callgraph (XRay, duh),
and there are already means to reconstruct it within `llvm-xray` tool.

This proposes to add a `-recursive-calls-only` switch to the `account` tool.
When the switch is on, when re-constructing callgraph for latency reconstruction,
each time we enter/leave some function, we increment/decrement an entry for the function
in a "recursion depth" map. If, when we leave the function, said entry was at `1`,
then that means the function didn't call itself, however if it is at `2` or more,
then that means the function (possibly indirectly) called itself.

If the depth is 1, we don't account the time spent there,
unless within this call stack the function already recursed into itself.
Note that we don't pay for recursion depth tracking when `recursive-calls-only` is not on,
and the perf impact is insignificant (+0.3% regression)

The overhead of the option is actually negative, around -5.26% user time on a medium-sized (3.5G) XRay log.
As a practical example, that 3.5G log is a capture of the entire middle-end opt pipeline
at `-O3` for RawSpeed unity build. There are total of `5500` functions in the log,
however `-recursive-calls-only` says that `269`, or 5%, are recursive.

Having this functionality could be helpful for recursion eradication.

Reviewers: dberris, mboerger

Reviewed By: dberris

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84582
2020-07-27 10:15:44 +03:00
Roman Lebedev
fa31e249cb [NFC][XRay] Account: migrate to DenseMap + SmallVector, -16% faster on large (3.8G) input
DenseMap is a single allocation underneath, so this is has pretty expected
performance impact on large-ish (3.8G) xray log processing time.
2020-07-26 14:08:07 +03:00
Roman Lebedev
2f9de5aa72 [NFC][XRay] Account: decouple getStats() interface from underlying data structure
It doesn't really need to know where Timings are stored, it just needs
to be able to sort them, so MutableArrayRef is enough.

That uncovers an interesting quirk that it relied on
implicit double->int conversion for calculating percentiles.
2020-07-26 14:08:06 +03:00
Roman Lebedev
eae3e5a494 [Reduce] Argument reduction: do deal with function declarations
We can happily turn function definitions into declarations,
thus obscuring their argument from being elided by this pass.

I don't believe there is a good reason to just ignore declarations.
likely even proper llvm intrinsics ones,
at worst the input becomes uninteresting.

The other question here is that all these transforms are all-or-nothing.
In some cases, should we be treating each use separately?

The main blocker here seemed to be that llvm::CloneFunctionInto()
does `&OldFunc->front()`, which inserts a nullptr into a densemap,
which is not happy about it and asserts.
2020-07-26 01:31:56 +03:00
Roman Lebedev
942c801f82 [Reduce] Argument reduction: do properly handle invoke insts (PR46819)
replaceFunctionCalls() is very non-exhaustive, it only handles
CallInst's. Which means, by the time we drop old function,
there may still be uses of it lurking around.
Let's instead whack-a-mole them by all by replacing with undef.

I'm not sure this is the best handling, especially for calls, but IMO
poorly reduced input is much better than crashing reduction tool.
A (previously-crashing!) test added.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46819
2020-07-26 01:29:00 +03:00
Roman Lebedev
c62f97f67d [Reduce] Basic block reduction: do properly handle invoke insts (PR46818)
Terminator may have returned value, so we need to replace uses,
and in general handle invoke as a branch inst.

I'm not sure this is the best handling, but IMO poorly reduced
input is much better than crashing reduction tool.
A (previously-crashing!) test added.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46818
2020-07-26 01:28:59 +03:00
Roman Lebedev
f9cbb7144f [Reduce] Try turning function definitions into declarations first, NFCI-ish
ReduceFunctions could do it, but it also replaces *all* calls with undef,
so if any of undef replacements makes reduction uninteresting,
it won't work.

ReduceBasicBlocks also could do it, but well, it may take many guesses
for all the blocks of a function to happen to be out-of-chunk,
which is not a very efficient way to go about it.

So let's just do this first.
2020-07-25 21:43:36 +03:00
Xing GUO
9f9286af5c [DWARFYAML] Replace 'Format', 'Version', etc with 'FormParams'. NFC.
This patch replaces 'Format', 'Version' fields, etc with 'FormParams' to
simplify codes.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D84496
2020-07-24 16:54:51 +08:00
Fangrui Song
4f0382f382 Add test utility 'extract'
See https://lists.llvm.org/pipermail/llvm-dev/2020-July/143373.html
"[llvm-dev] Multiple documents in one test file" for some discussions.

`extract part filename` splits the input file into multiple parts separated by
regex `^(.|//)--- ` and extract the specified part to stdout or the
output file (if specified).

Use case A (organizing input of different formats (e.g. linker
script+assembly) in one file).

```
// RUN: extract lds %s -o %t.lds
// RUN: extract asm %s -o %t.s
// RUN: llvm-mc %t.s -o %t.o
// RUN: ld.lld -T %t.lds %t.o -o %t
This is sometimes better than the %S/Inputs/ approach because the user
can see the auxiliary files immediately and don't have to open another file.
```

Use case B (for utilities which don't have built-in input splitting
feature):

```
// RUN: extract case1 %s | llc | FileCheck %s --check-prefix=CASE1
// RUN: extract case2 %s | llc | FileCheck %s --check-prefix=CASE2
Combing tests prudently can improve readability.
This is sometimes better than having multiple test files.
```

Since this is a new utility, there is no git history concerns for
UpperCase variable names. I use lowerCase variable names like mlir/lld.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D83834
2020-07-23 19:15:35 -07:00
Craig Topper
cd59b87053 [bugpoint] Fix typo in assertion message. NFC 2020-07-23 16:06:43 -07:00
Georgii Rymar
c069c24df3 [llvm-readelf] - Simplify the implementation of getSectionTypeString() helper. NFCI.
It is used for printing section headers in the GNU style
and the implementation can be simplified.

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

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

Reviewers: dblaikie, nickdesaulniers, diegotf

Reviewed By: dblaikie

Subscribers: llvm-commits

Tags: #llvm

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

This patch will NOT the default behavior.

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

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

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

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

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

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

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

This is what this patch does.

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

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

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

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

Reviewed by alexshap, smeenai, jhenderson

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

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

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

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

Reviewed By: ychen

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

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

Reviewed By: grimar, jhenderson

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

The motivation for this is D82547.

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

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

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

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

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

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

Reviewed By: tejohnson

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

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

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

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

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

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

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

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

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

Reviewed By: lebedev.ri

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

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

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

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

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

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

Reviewed By: vitalybuka

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

Reviewed by alexshap, smeenai, jhenderson, MaskRay

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

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

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

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

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

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

Reviewed By: jdoerfert

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

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

This patch addresses issues mentioned.

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

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

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

Reviewed By: asbirlea

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

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

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

This patch adds a test and fixes the behavior.

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

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

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

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

Reviewed By: nickdesaulniers

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

Tags: #llvm

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

Reviewers: dblaikie, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

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

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

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

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

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

Reviewed By: hans

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

Reviewed By: hans

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

Reviewed By: echristo

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

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

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

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

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

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

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

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

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

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

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

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

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

This patch addresses both these points.

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

It makes the code more readable and consistent.

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

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

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

The patch fixes this issue.

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

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

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

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

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

Reviewed By: nickdesaulniers

Subscribers: hiraditya, mgorny, llvm-commits

Tags: #llvm

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

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

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

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

Reviewed By: smeenai

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

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

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

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

Reviewed By: jhenderson

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

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

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

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

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

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

In other words, if we have

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

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

This patch helps resolve this problem.

Reviewed By: jhenderson

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

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

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

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

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

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

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

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

Reviewed By: xiangzhangllvm

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

Differential Revision: https://reviews.llvm.org/D82479
2020-07-01 12:02:32 +01:00