1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
Commit Graph

11033 Commits

Author SHA1 Message Date
Fangrui Song
69fe3b46f5 [yaml2obj] Rename SHOffset (e_shoff) field to SHOff. NFC
`struct Elf*_Shdr` has a field `sh_offset`, named `ShOffset` in
llvm::ELFYAML::Section. Rename SHOffset (e_shoff) to SHOff to prevent confusion.

Reviewed By: grimar

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

llvm-svn: 371185
2019-09-06 09:23:17 +00:00
Fangrui Song
2a1caa980a [llvm-readobj][yaml2obj] Support SHT_LLVM_SYMPART, SHT_LLVM_PART_EHDR and SHT_LLVM_PART_PHDR
See http://lists.llvm.org/pipermail/llvm-dev/2019-February/130583.html
and D60242 for the lld partition feature.

This patch:

* Teaches yaml2obj to parse the 3 section types.
* Teaches llvm-readobj/llvm-readelf to dump the 3 section types.

There is no test for SHT_LLVM_DEPENDENT_LIBRARIES in llvm-readobj. Add
it as well.

Reviewed By: thakis

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

llvm-svn: 371157
2019-09-06 00:53:28 +00:00
George Rimar
2e7c3b12d7 [llvm-readelf] - Allow dumping dynamic symbols when there is no program headers.
D62179 introduced a regression. llvm-readelf lose the ability to dump the dynamic symbols
when there is .dynamic section with a DT_SYMTAB, but there are no program headers:
https://reviews.llvm.org/D62179#1652778

Below is a program flow before the D62179 change:

1) Find SHT_DYNSYM.
2) Find there is no PT_DYNAMIC => don't try to parse it.
3) Print dynamic symbols using information about them found on step (1).

And after the change it became:

1) Find SHT_DYNSYM.
2) Find there is no PT_DYNAMIC => find SHT_DYNAMIC.
3) Parse dynamic table, but fail to handle the DT_SYMTAB because of the absence of the PT_LOAD. Report the "Virtual address is not in any segment" error.

This patch fixes the issue. For doing this it checks that the value of DT_SYMTAB was
mapped to a segment. If not - it ignores it.

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

llvm-svn: 371071
2019-09-05 14:02:58 +00:00
Lang Hames
9360dc80d5 [llvm-rtdyld][llvm-jitlink] Rename struct member to remove ambiguity.
This ambiguity (struct member name matching struct name) was causing errors on
a few of the MSVC bots. Hopefully this should fix it.

llvm-svn: 370969
2019-09-04 20:26:26 +00:00
Lang Hames
300f0ca1fd [llvm-rtdyld] Add timers to match llvm-jitlink.
When using llvm-rtdyld to execute code, -show-times will now show the time
taken to load the object files, apply relocations, and execute the
rtdyld-linked code.

llvm-svn: 370968
2019-09-04 20:26:25 +00:00
Lang Hames
b407768dfe [JITLink] Fix the show-timers option on llvm-jitlink.
No longer constantly shows times (even when -show-times=false). When shown,
times are now correctly grouped.

llvm-svn: 370951
2019-09-04 18:38:29 +00:00
Simon Pilgrim
0e2da37a16 Fix "enumeral and non-enumeral type in conditional expression" warnings. NFCI.
llvm-svn: 370892
2019-09-04 12:51:40 +00:00
Djordje Todorovic
4991da1e85 [llvm-dwarfdump] Fix spelling in the comments. NFC
llvm-svn: 370861
2019-09-04 09:44:09 +00:00
Fangrui Song
612176f1b2 [llvm-objcopy] Add objcopy:🧝:Object::allocSections to simplify loops on SHF_ALLOC sections
Reviewed By: jhenderson

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

llvm-svn: 370860
2019-09-04 09:35:32 +00:00
Fangrui Song
786f32fbda [llvm-objcopy] Rename variable names "Section" to "Sec". NFC
"Section" can refer to the type llvm::objcopy:🧝:Section or the
variable name. Rename it to "Sec" for clarity. "Sec" is already used a
lot, so this change improves consistency as well.

Also change `auto` to `const SectionBase` for readability.

Reviewed By: grimar

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

llvm-svn: 370852
2019-09-04 08:43:27 +00:00
Fangrui Song
374144cad0 [llvm-objcopy] Fix some identifier names in comments. NFC
llvm-svn: 370838
2019-09-04 03:54:43 +00:00
Vedant Kumar
6f6a5a74b9 [llvm-profdata] Add mode to recover from profile read failures
Add a mode in which profile read errors are not immediately treated as
fatal. In this mode, merging makes forward progress and reports failure
only if no inputs can be read.

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

llvm-svn: 370827
2019-09-03 22:23:16 +00:00
Fangrui Song
c10555e1fa [llvm-objcopy] Simplify alignToAddr with llvm::alignTo
llvm-svn: 370577
2019-08-31 10:48:09 +00:00
Wei Mi
f59cc38992 Fix some errors introduced by rL370563 which were not exposed on my local machine.
1. zlib::compress accept &size_t but the param is an uint64_t.
2. Some systems don't have zlib installed. Don't use compression by default.

llvm-svn: 370564
2019-08-31 03:17:49 +00:00
Wei Mi
47e2f8a30e [SampleFDO] Add profile symbol list section to discriminate function being
cold versus function being newly added.

This is the second half of https://reviews.llvm.org/D66374.

Profile symbol list is the collection of function symbols showing up in
the binary which generates the current profile. It is used to discriminate
function being cold versus function being newly added. Profile symbol list
is only added for profile with ExtBinary format.

During profile use compilation, when profile-sample-accurate is enabled,
a function without profile will be regarded as cold only when it is
contained in that list.

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

llvm-svn: 370563
2019-08-31 02:27:26 +00:00
David Blaikie
1f0c809cef llvm-dwarfdump: Cache CU low_pc when computing statistics.
llvm-svn: 370559
2019-08-31 01:05:46 +00:00
Puyan Lotfi
31a7e50db7 [IFS][NFC] llvm-ifs: Fixing build bot build break: revert r370517 and r370510.
llvm-svn: 370522
2019-08-30 20:25:46 +00:00
Puyan Lotfi
d63fc8cc9e [IFS][NFC] llvm-ifs: Fixing build bot error due to commit conflicts.
r370510 and r370504

Again only on gcc.

llvm-svn: 370517
2019-08-30 20:09:55 +00:00
Puyan Lotfi
0d053c126a [IFS][NFC] llvm-ifs: Fixing build errors for bots using GCC.
gcc produces the error:

error: specialization of
‘template<class T, class Enable> struct llvm::yaml::ScalarTraits’ in
different namespace

For all specializations outside of llvm::yaml. So I added llvm::yaml to these
specializations to fix the errors on the bots building with gcc (/usr/bin/c++).

llvm-svn: 370510
2019-08-30 19:54:46 +00:00
Michael Liao
ab94c7a42e Fix compilation warnings. NFC.
llvm-svn: 370504
2019-08-30 19:23:28 +00:00
Puyan Lotfi
e0c741cd7e [llvm-ifs][IFS] llvm Interface Stubs merging + object file generation tool.
This tool merges interface stub files to produce a merged interface stub file
or a stub library. Currently it for stub library generation it can produce an
ELF .so stub file, or a TBD file (experimental). It will be used by the clang
-emit-interface-stubs compilation pipeline to merge and assemble the per-CU
stub files into a stub library.

The new IFS format is as follows:

--- !experimental-ifs-v1
IfsVersion:      1.0
Triple:          <llvm triple>
ObjectFileFormat: <ELF | TBD>
Symbols:
  _ZSymbolName: { Type: <type>, etc... }
...

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

llvm-svn: 370499
2019-08-30 18:26:05 +00:00
Sid Manning
439ff91bbd [llvm-nm] Small fix to Exected<StringRef>
Differential Revision: https://reviews.llvm.org/D66976

llvm-svn: 370474
2019-08-30 14:12:04 +00:00
Chris Jackson
4d8ae1bdd7 [llvm-objcopy] Allow the visibility of symbols created by --binary and
--add-symbol to be specified with --new-symbol-visibility

llvm-svn: 370458
2019-08-30 10:17:16 +00:00
Martin Storsjo
5e8195f9a7 [COFF] Add a ResourceSectionRef method for getting resource contents
This allows llvm-readobj to print the contents of each resource
when printing resources from an object file or executable, like it
already does for plain .res files.

This requires providing the whole COFFObjectFile to ResourceSectionRef.

This supports both object files and executables. For executables,
the DataRVA field is used as is to look up the right section.

For object files, ideally we would need to complete linking of them
and fix up all relocations to know what the DataRVA field would end up
being. In practice, the only thing that makes sense for an RVA field
is an ADDR32NB relocation. Thus, find a relocation pointing at this
field, verify that it has the expected type, locate the symbol it
points at, look up the section the symbol points at, and read from the
right offset in that section.

This works both for GNU windres object files (which use one single
.rsrc section, with all relocations against the base of the .rsrc
section, with the original value of the DataRVA field being the
offset of the data from the beginning of the .rsrc section) and
cvtres object files (with two separate .rsrc$01 and .rsrc$02 sections,
and one symbol per data entry, with the original pre-relocated DataRVA
field being set to zero).

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

llvm-svn: 370433
2019-08-30 06:55:49 +00:00
Dan Gohman
f73e4af6a5 [WebAssembly] Make __attribute__((used)) not imply export.
Add an WASM_SYMBOL_NO_STRIP flag, so that __attribute__((used)) doesn't
need to imply exporting. When targeting Emscripten, have
WASM_SYMBOL_NO_STRIP imply exporting.

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

llvm-svn: 370415
2019-08-29 22:40:00 +00:00
George Rimar
2fdfc9c726 [llvm-readobj/llvm-readelf] - Report a proper warning when dumping a broken dynamic relocation.
When we have a dynamic relocation with a broken symbol's st_name,
tools report a useless error: "Invalid data was encountered while parsing the file".

After this change we report a warning + "<corrupt>" as a symbol name.

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

llvm-svn: 370330
2019-08-29 10:55:57 +00:00
Martin Storsjo
bf8066642b [COFF] Add a ResourceSectionRef method for getting the data entry, print it in llvm-readobj
Differential Revision: https://reviews.llvm.org/D66819

llvm-svn: 370311
2019-08-29 09:00:14 +00:00
Martin Storsjo
bd120308fe [COFF] Add a bounds checking helper for iterating a coff_resource_dir_table
Instead of blindly incrementing pointers in llvm-readobj, use this
helper, which does bounds checking against the available section
data.

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

llvm-svn: 370310
2019-08-29 08:59:56 +00:00
Martin Storsjo
d8efa4c264 [llvm-readobj] Print the resource type textually for .res files
This already is done when dumping resources from coff objects.

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

llvm-svn: 370308
2019-08-29 08:59:31 +00:00
Martin Storsjo
55054ce46f [llvm-readobj] Remove a leftover string trim operation. NFC.
This became unnecessary in SVN r359153.

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

llvm-svn: 370307
2019-08-29 08:59:05 +00:00
Vitaly Buka
88ec345e4b [ObjectYAML] Fix lifetime issue in dumpDebugLines
Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 370289
2019-08-29 02:36:48 +00:00
Tom Stellard
44e6afe5ae [LLVM-C] Fix omission of INSTALL_WITH_TOOLCHAIN to llvm_add_library()
Due to a misstake with r365902 that tried to simplify the install with
toolchain logic LLVM-C.dll was no longer being installed.

Patch By: Jakob Bornecrantz

llvm-svn: 370271
2019-08-28 22:59:04 +00:00
Jason Liu
3989e2a0ae [llvm-readobj][XCOFF][NFC] Add return statement to avoid -Wimplicit-fallthrough warning
This is to fix the commit in r370097.

llvm-svn: 370260
2019-08-28 20:59:17 +00:00
Jason Liu
fd2aefafba [XCOFF][AIX] Generate symbol table entries with llvm-readobj
Summary:

This patch implements main entry and auxiliary entries of symbol table generation for llvm-readobj on AIX.
The source code of aix_xcoff_xlc_test8.o (compile with xlc) is:

-bash-4.2$ cat test8.c
extern int i;
extern int TestforXcoff;
extern int fun(int i);
static int static_i;
char* p="abcd";
int fun1(int j) {
  static_i++;
  j++;
  j=j+*p;
  return j;
}
int main() {
  i++;
  fun(i);
  return fun1(i);
}

Patch provided by DiggerLin

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

llvm-svn: 370097
2019-08-27 18:54:46 +00:00
Reid Kleckner
fa08039609 Revert Autogenerate the shebang lines for tools/opt-viewer
This reverts r369486 (git commit 8d18384809957cc923752e10a86adab129e3df48)

The opt-viewer tests don't pass after this change, and fixing them isn't
trivial. opt-viewer.py imports optmap, which requires adjusting
pythonpath, which is more work than I'm willing to do to fix forward.

llvm-svn: 370095
2019-08-27 18:31:29 +00:00
Lang Hames
29ae644374 [JITLink] Fix bogus TimerGroup constructor call.
llvm-svn: 370088
2019-08-27 18:05:05 +00:00
Lang Hames
16a076c3d8 [JITLink] Add timers and -show-times option to llvm-jitlink.
The timers track time spent loading objects, linking, and (if applicable)
running JIT-link'd code.

llvm-svn: 370075
2019-08-27 15:51:19 +00:00
George Rimar
fd160d7de0 [llvm-objdump] - Remove one overload of reportError. NFCI.
There is a problem with reportError we have.
Declaration says we have ArchiveName
that follows the FileName:

reportError(Error E, StringRef FileName, StringRef ArchiveName,...

Though implementation have them reversed. I cleaned it up and
removed an excessive reportError(Error E, StringRef File) version.

Rebased on top of D66418.

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

llvm-svn: 370034
2019-08-27 10:03:45 +00:00
Gabor Buella
2db44ec9ef [NFC][cmake] Build fix in tools/llvm-config/CMakeLists.txt
To avoid the following error message (using cmake version 3.13.4) :

```
CMake Error at tools/llvm-config/CMakeLists.txt:37 (string):
Syntax error in cmake code  when parsing string-std=[^ ]\+Invalid escape sequence \+
```

Reviewed By: mgorny

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

llvm-svn: 369887
2019-08-26 09:42:30 +00:00
Benjamin Kramer
d474a8b811 [llvm-reduce] Silence -Wdocumentation
ReduceGlobalVars.cpp:17:6: warning: '@returns' command used in a comment that is attached to a function returning void

llvm-svn: 369848
2019-08-24 15:04:33 +00:00
Wei Mi
77474d769d [SampleFDO] Add ExtBinary format to support extension of binary profile.
This is a patch split from https://reviews.llvm.org/D66374. It tries to add
a new format of profile called ExtBinary. The format adds a section header
table to the profile and organize the profile in sections, so the future
extension like adding a new section or extending an existing section will be
easier while keeping backward compatiblity feasible.

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

llvm-svn: 369798
2019-08-23 19:05:30 +00:00
Jordan Rupprecht
854147d0cc [llvm-objcopy] Strip debug sections when running with --strip-unneeded.
Summary:
GNU --strip-unneeded strips debugging sections as well. Do that for llvm-objcopy as well.

Additionally, add a test that verifies we keep the .gnu_debuglink section. This apparently was not always the case, and I'm not sure which commit fixed it, but there doesn't appear to be any test coverage to make sure we continue to do so.

This fixes PR41043.

Reviewers: jhenderson, jakehehrlich, espindola, alexshap

Subscribers: emaste, arichardson, MaskRay, abrachet, seiya, llvm-commits

Tags: #llvm

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

llvm-svn: 369761
2019-08-23 14:28:58 +00:00
Benjamin Kramer
3b8f63172a Fight a bit against global initializers. NFC.
llvm-svn: 369695
2019-08-22 19:43:27 +00:00
Jordan Rupprecht
b1afc0dedc [llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.

To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.

Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap

Reviewed By: jhenderson, MaskRay

Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits

Tags: #llvm

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

llvm-svn: 369689
2019-08-22 19:17:50 +00:00
George Rimar
f05e457a4a [llvm-readobj] - Remove reportError(std::error_code EC, StringRef Input) helper.
We do not need it, std::error_code is used mostly for COFF and
this patch rewrites the calls to use a different overload.

Having reportError(std::error_code EC, ... is excessive by itself,
because API that use error codes actually needs refactoring to
use Error/Expected<> instead.

DIfferential revision: https://reviews.llvm.org/D66521

llvm-svn: 369630
2019-08-22 08:56:24 +00:00
George Rimar
79796ed688 [llvm-objdump] - Cleanup the error reporting.
The error reporting function are not consistent.

Before this change:

* They had inconsistent naming (e.g. 'error' vs 'report_error').
* Some of them reported the object name, others - dont.
* Some of them accepted the case when there was no error. (i.e. error code or Error had a success value).

This patch tries to cleanup it a bit.

It also renames report_error -> reportError, report_warning -> reportWarning
and removes a full stop from messages.

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

llvm-svn: 369515
2019-08-21 11:07:31 +00:00
Chris Bieneman
91c7b0fa0a Autogenerate the shebang lines for tools/opt-viewer
Summary:
Since these files depend on the built python modules, they need to use
the right python binary to run them. So use configure_file
to set the right shebang line.

Patch By: cbiesinger (Christian Biesinger)

Reviewers: chandlerc, beanz, anemet

Reviewed By: anemet

Subscribers: compnerd, JDevlieghere, mgorny, llvm-commits

Tags: #llvm

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

llvm-svn: 369486
2019-08-21 01:48:28 +00:00
Jinsong Ji
fa4131d59e [llvm-extract] Update the help message for group extraction feature
Summary:
https://reviews.llvm.org/D60973 exposed the group extraction feature of
the BlockExtractor to llvm-extract.
However, the help message was not updated, so users might not be able to
know how to use this feature without looking into history/commits.

This patch just update the help message to show how to use this group
extraction feature.

Reviewers: qcolombet, volkan

Reviewed By: qcolombet

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 369438
2019-08-20 20:45:16 +00:00
Fangrui Song
b0559dae5f [llvm-objcopy] Append '\n' to warning messages
Currently the warning message of `llvm-strip %t.o %t.o` does not include
the trailing newline. Fix this by appending a '\n'.

This is the only warning llvm-objcopy and llvm-strip can issue.

Reviewed By: jhenderson

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

llvm-svn: 369391
2019-08-20 15:00:07 +00:00
George Rimar
816a7c4f33 [llvm-objdump] - Remove one of report_error functions and improve the error reporting.
One of the report_error functions was taking object::Archive::Child as an
argument. It feels excessive, this patch removes it and introduce a helper
function instead. Also I fixed a "TODO" in this patch what improved the message printed.

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

llvm-svn: 369382
2019-08-20 13:19:16 +00:00
Fangrui Song
b648113afa [llvm-readobj] Prepend argv[0] to error/warning messages
Summary:
Currently, we report:

    error: ...

Prepend argv[0] (tool name):

    llvm-readobj: error: ...

This is consistent with most GNU binutils/clang/lld, and gives a bit
more context in a long build log.

Reviewed By: grimar, jhenderson, rupprecht

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

llvm-svn: 369377
2019-08-20 12:49:15 +00:00
Simon Pilgrim
e0da28268f Fix MSVC "result of 32-bit shift implicitly converted to 64 bits" warning. NFCI.
llvm-svn: 369366
2019-08-20 10:25:57 +00:00
Seiya Nuta
52efdb7adc [yaml2obj/obj2yaml][MachO] Allow setting custom section data
Reviewers: alexshap, jhenderson, rupprecht

Reviewed By: alexshap, jhenderson

Subscribers: abrachet, hiraditya, llvm-commits

Tags: #llvm

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

llvm-svn: 369348
2019-08-20 08:49:07 +00:00
Seiya Nuta
d6e74f9c7c [llvm-objcopy][MachO] Fix method names. NFC.
Reviewers: alexshap, rupprecht, jhenderson

Reviewed By: alexshap, rupprecht

Subscribers: jakehehrlich, abrachet, llvm-commits

Tags: #llvm

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

llvm-svn: 369346
2019-08-20 08:36:47 +00:00
Hubert Tong
f12628ef2a [cmake] Link in LLVMPasses due to dependency by LLVMOrcJIT; NFC
Summary:
rL367756 (f5c40cb) increases the dependency of LLVMOrcJIT on LLVMPasses.
In particular, symbols defined in LLVMPasses that are referenced by the
destructor of `PassBuilder` are now referenced by LLVMOrcJIT through
`Speculation.cpp.o`.

We believe that referencing symbols defined in LLVMPasses in the
destructor of `PassBuilder` is valid, and that adding to the set of such
symbols is legitimate. To support such cases, this patch adds LLVMPasses
to the set of libraries being linked when linking in LLVMOrcJIT causes
such symbols from LLVMPasses to be referenced.

Reviewers: Whitney, anhtuyen, pree-jackie

Reviewed By: pree-jackie

Subscribers: mgorny, llvm-commits

Tags: #llvm

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

llvm-svn: 369310
2019-08-19 23:12:48 +00:00
Seiya Nuta
aba5322f2a Recommit "[llvm-objcopy][MachO] Implement a layout algorithm for executables"
Summary: The layout algorithm for relocatable objects and for executable are somewhat different. This patch implements the latter one based on the algorithm in LLD (MachOFileLayout).

Reviewers: alexshap, rupprecht, jhenderson

Reviewed By: alexshap

Subscribers: jakehehrlich, abrachet, llvm-commits

Tags: #llvm

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

llvm-svn: 369301
2019-08-19 21:12:02 +00:00
Seiya Nuta
c44c8db652 Recommit "[llvm-objcopy][MachO] Support load commands used in executables/shared libraries"
Summary:
This patch implements copying some load commands that appear in executables/shared libraries such as the indirect symbol table.

I don't add tests intentionally because this patch is incomplete: we need a layout algorithm for executables/shared libraries. I'll submit it as a separate patch with tests.

Reviewers: alexshap, rupprecht, jhenderson, compnerd

Reviewed By: alexshap

Subscribers: abrachet, mgorny, mgrang, MaskRay, mtrent, jakehehrlich, llvm-commits

Tags: #llvm

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

llvm-svn: 369298
2019-08-19 21:05:31 +00:00
George Rimar
71e346cddb [llvm-objdump] - Restore lost comment.
It was removed by mistake in r369263 (D66417).

llvm-svn: 369265
2019-08-19 14:35:08 +00:00
George Rimar
4603392e6d [Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.
There are 4 methods that return std::error_code now,
though they do not have to because they are always succeed.
I refactored them.

This allows to simplify the code in tools a bit.

llvm-svn: 369263
2019-08-19 14:32:23 +00:00
Fangrui Song
38bfad8962 [llvm-readobj] unwrapOrError: remove unnecessary llvm_unreachable after r369194
llvm-svn: 369254
2019-08-19 12:18:18 +00:00
Seiya Nuta
1d8663f8f0 Revert r369230 and r369231
Looks these commits break CI builds:

- http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-gn/builds/4159

This commit reverts r369230 and r369231 (git coommit: 4a198a7 and dee9546).

llvm-svn: 369234
2019-08-19 06:45:48 +00:00
Seiya Nuta
64fc8e3ce8 [llvm-objcopy][MachO] Implement a layout algorithm for executables
Summary: The layout algorithm for relocatable objects and for executable are somewhat different. This patch implements the latter one based on the algorithm in LLD (MachOFileLayout).

Reviewers: alexshap, rupprecht, jhenderson

Reviewed By: alexshap

Subscribers: jakehehrlich, abrachet, llvm-commits

Tags: #llvm

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

llvm-svn: 369231
2019-08-19 05:41:33 +00:00
Seiya Nuta
1102d0b0b8 [llvm-objcopy][MachO] Support load commands used in executables/shared libraries
Summary:
This patch implements copying some load commands that appear in executables/shared libraries such as the indirect symbol table.

I don't add tests intentionally because this patch is incomplete: we need a layout algorithm for executables/shared libraries. I'll submit it as a separate patch with tests.

Reviewers: alexshap, rupprecht, jhenderson, compnerd

Reviewed By: alexshap

Subscribers: abrachet, mgorny, mgrang, MaskRay, mtrent, jakehehrlich, llvm-commits

Tags: #llvm

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

llvm-svn: 369230
2019-08-19 05:37:38 +00:00
George Rimar
09776aab5d Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API."
Fix: Add a `consumeError` call removed by mistake to 'printStackSize',
this should fix the "Expected<T> must be checked before access or destruction." reported by following bot:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio

Original commit message:
Currently we have the following functions for error reporting:

LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input); 
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);

Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.

After applying this patch we have:

void reportError(Error Err, StringRef Input); 
void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);

I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.

Test cases were updated, they show an improvement introduced.

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

llvm-svn: 369194
2019-08-17 16:07:18 +00:00
George Rimar
602860ff2d Revert r369190, r369192 ([llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API.)
It caused multiple BB failtures:

http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/26042/steps/ninja%20check%201/logs/FAIL%3A%20LLVM%3A%3Astack-sizes.test

llvm-svn: 369193
2019-08-17 15:36:06 +00:00
George Rimar
b3d7c26aa4 [llvm-readobj] - An attemp to fix BB after r369191.
Few BB failed with the following error:

Command Output (stderr):
--
/home/buildbots/ppc64be-clang-lnt-test/clang-ppc64be-lnt/llvm/test/tools/llvm-readobj/stack-sizes.test:263:19: error: BADSECTION-OUT: expected string not found in input
# BADSECTION-OUT: 8 ?
                  ^
<stdin>:4:1: note: scanning from here

^

It doesn't reproduce on ubuntu/windows I have. Also, seems many of the bots
are happy too.

This slightly reorders the code to make fouts().flush() call earlier,
like it was before the r369191.

llvm-svn: 369192
2019-08-17 15:24:16 +00:00
George Rimar
bdd80e6afb [llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API.
urrently we have the following functions for error reporting:

--
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input); 
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);
---

Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.

After applying this patch we have:

---
LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input); 
LLVM_ATTRIBUTE_NORETURN void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);
---

I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.

Test cases were updated, they show an improvement introduced.

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

llvm-svn: 369190
2019-08-17 14:36:40 +00:00
Petr Hosek
353f33d2f8 [llvm-readobj] Unwrap the value first to avoid the error
This addresses the issue introduced in r369169, we need to unwrap
the value first before we can check whether it's empty. This also
swaps the two branches to put the common path first which should
be NFC.

llvm-svn: 369177
2019-08-17 00:07:26 +00:00
Petr Hosek
e14c8f4aaf [llvm-readobj] Fallback to PT_NOTE if file doesn't have sections
This is useful when trying to read notes from stripped files and matches
the behavior of GNU readelf and eu-readelf.

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

llvm-svn: 369169
2019-08-16 23:15:40 +00:00
Jordan Rose
91397b21be Fix llvm-config support for CMake build-mode-style builds
At some point we and/or CMake changed our build-mode-style builds from
  $LLVM_OBJ_ROOT/bin/$CMAKE_CFG_INTDIR/
to
  $LLVM_OBJ_ROOT/$CMAKE_CFG_INTDIR/bin/
which is way easier to use. But no one updated llvm-config.

https://reviews.llvm.org/D66326

llvm-svn: 369129
2019-08-16 17:17:45 +00:00
Diego Trevino Ferrer
fab54799c5 [Bugpoint redesign] Added Pass to Remove Global Variables
Summary:
This pass tries to remove Global Variables, as well as their derived uses. For example if a variable `@x` is used by `%call1` and `%call2`, both these uses and the definition of `@x` are deleted. Moreover if `%call1` or `%call2` are used elsewhere those uses are also deleted, and so on recursively.

I'm still uncertain if this pass should remove derived uses, I'm open to suggestions.

Subscribers: mgorny, llvm-commits

Tags: #llvm

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

> llvm-svn: 368918

llvm-svn: 369061
2019-08-15 22:54:09 +00:00
Diego Trevino Ferrer
f3ddd9e99c [Bugpoint redesign] Output option can now print to STDOUT
Summary:
This also changes all the outs() statements to errs() so the output and
progress streams don't get mixed.

This has been added because D64176 had flaky tests, which I believe were because the reduced file was being catted into `FileCheck`, instead of being pass from STDOUT directly.

Reviewers: chandlerc, dblaikie, xbolva00

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 369060
2019-08-15 22:39:43 +00:00
JF Bastien
3fcfd786dd Fix nm on GCC 5.1 after the C++14 move
Summary:
As in D66306, fix the invocation of std::sort with std::function by not using
std::function, since it's easier to read and is broken in libstdc++ from GCC 5.1
(see https://gcc.gnu.org/PR65942).

Reviewers: thakis

Subscribers: jkorous, mgrang, dexonsmith, rupprecht, llvm-commits

Tags: #llvm

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

llvm-svn: 369045
2019-08-15 20:38:42 +00:00
Diego Trevino Ferrer
f97adebbab Revert [Bugpoint redesign] Added Pass to Remove Global Variables
This reverts r368918 because it was unstable!

It broke these builds:
 * http://lab.llvm.org:8011/builders/lld-x86_64-ubuntu-fast/builds/4649
 * http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/29966
 * http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/29964

But surprisingly this passed:
 * http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/29965

llvm-svn: 369039
2019-08-15 19:08:15 +00:00
Jonas Devlieghere
2c693415b7 [llvm] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

llvm-svn: 369013
2019-08-15 15:54:37 +00:00
Benjamin Kramer
33caf354b4 Bump llvm-go to C++14
llvm-svn: 368989
2019-08-15 10:55:25 +00:00
Chris Jackson
6712b2c77c [llvm-objcopy] Allow 'protected' visibility to be set when using
add-symbol

Reviewers: Maskray, rupprecht

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

llvm-svn: 368982
2019-08-15 09:45:09 +00:00
Seiya Nuta
4765c562bd [llvm-readobj][MachO] Fix section type printing
Summary:
Currently, llvm-readobj mistakenly decodes section type as section attribute.

This patch fixes the bug and affected tests.

Reviewers: JDevlieghere, jhenderson, rupprecht, alexshap, echristo

Reviewed By: jhenderson, rupprecht, alexshap, echristo

Subscribers: javed.absar, rupprecht, llvm-commits

Tags: #llvm

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

llvm-svn: 368974
2019-08-15 07:22:04 +00:00
Michael Pozulp
645a1056cd [llvm-objdump] Add warning messages if disassembly + source for problematic inputs
Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=41905

Reviewers: jhenderson, rupprecht, grimar

Reviewed By: jhenderson, grimar

Subscribers: RKSimon, MaskRay, hiraditya, llvm-commits

Tags: #llvm

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

llvm-svn: 368963
2019-08-15 05:15:22 +00:00
Michael Pozulp
40deb5ad19 [llvm-objcopy] Move duplicate tablegen from objcopy and strip into one file
Summary: This avoids maintaining the same options in two different places.

Reviewers: jhenderson, alexshap, rupprecht, MaskRay

Reviewed By: jhenderson, rupprecht, MaskRay

Subscribers: MaskRay, wolfgangp, jakehehrlich, abrachet, llvm-commits

Tags: #llvm

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

llvm-svn: 368961
2019-08-15 04:45:41 +00:00
Jonas Devlieghere
03772ca789 [NFC] Remove documentation comment to fix warning.
Remove the @return to fix the warning: '@returns' command used in a
comment that is attached to a function returning void [-Wdocumentation]

llvm-svn: 368957
2019-08-15 04:09:00 +00:00
Jonas Devlieghere
4388784b37 Revert "Expose TailCallKind via the LLVM C API"
This is failing on several build bots. Reverting as discussed in
https://reviews.llvm.org/D66061.

llvm-svn: 368953
2019-08-15 03:49:51 +00:00
Robert Widmann
f05ec670a4 Expose TailCallKind via the LLVM C API
Summary: This exposes `CallInst`'s tail call kind via new `LLVMGetTailCallKind` and `LLVMSetTailCallKind` functions. The motivation for this is to be able to see `musttail` for languages that require mandatory tail calls for correctness. Today only the weaker `LLVMSetTail` is exposed and there is no way to set `GuaranteedTailCallOpt` via the C API.

Reviewers: CodaFi, jyknight, deadalnix, rnk

Reviewed By: CodaFi

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

llvm-svn: 368945
2019-08-14 23:54:35 +00:00
Diego Trevino Ferrer
d97a9e1281 [Bugpoint redesign] Modified Functions pass to consider declarations
Summary: This modification was put in place so the `ReduceMetadata` pass doesn't have to consider debug functions

Reviewers: dblaikie

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 368934
2019-08-14 22:22:37 +00:00
Diego Trevino Ferrer
1b3c98cfd0 [Bugpoint redesign] Added Pass to Remove Global Variables
Summary:
This pass tries to remove Global Variables, as well as their derived uses. For example if a variable `@x` is used by `%call1` and `%call2`, both these uses and the definition of `@x` are deleted. Moreover if `%call1` or `%call2` are used elsewhere those uses are also deleted, and so on recursively.

I'm still uncertain if this pass should remove derived uses, I'm open to suggestions.

Subscribers: mgorny, llvm-commits

Tags: #llvm

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

llvm-svn: 368918
2019-08-14 21:01:19 +00:00
Diego Trevino Ferrer
339b24fbc2 [Bugpoint redesign] Reduced scope of variables in Delta implementation
Summary: This diff also changed the check in `Delta.cpp` to verify interesting-ness, so it exits when the input isn't interesting

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 368915
2019-08-14 20:34:12 +00:00
George Rimar
21610566c8 Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
Changes: no changes. A fix for the clang code will be landed right on top.

Original commit message:

SectionRef::getName() returns std::error_code now.
Returning Expected<> instead has multiple benefits.

For example, it forces user to check the error returned.
Also Expected<> may keep a valuable string error message,
what is more useful than having a error code.
(Object\invalid.test was updated to show the new messages printed.)

This patch makes a change for all users to switch to Expected<> version.

Note: in a few places the error returned was ignored before my changes.
In such places I left them ignored. My intention was to convert the interface
used, and not to improve and/or the existent users in this patch.
(Though I think this is good idea for a follow-ups to revisit such places
and either remove consumeError calls or comment each of them to clarify why
it is OK to have them).

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

llvm-svn: 368826
2019-08-14 11:10:11 +00:00
George Rimar
f64562dc67 Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455

llvm-svn: 368813
2019-08-14 08:56:55 +00:00
George Rimar
3a9b0e354d [llvm/Object] - Convert SectionRef::getName() to return Expected<>
SectionRef::getName() returns std::error_code now.
Returning Expected<> instead has multiple benefits.

For example, it forces user to check the error returned.
Also Expected<> may keep a valuable string error message,
what is more useful than having a error code.
(Object\invalid.test was updated to show the new messages printed.)

This patch makes a change for all users to switch to Expected<> version.

Note: in a few places the error returned was ignored before my changes.
In such places I left them ignored. My intention was to convert the interface
used, and not to improve and/or the existent users in this patch.
(Though I think this is good idea for a follow-ups to revisit such places
and either remove consumeError calls or comment each of them to clarify why
it is OK to have them).

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

llvm-svn: 368812
2019-08-14 08:46:54 +00:00
Alex Langford
88fae211c4 [NFCI] Explicitly provide user-defined constructor for SectionRef
I am changing this to work around an issue that is being hit when
building with clang 3.8. Specifically, clang 3.8 requires that we have a user
defined default constructor for SectionRef for the default initialization of a
const SectionRef.

llvm-svn: 368758
2019-08-13 22:16:18 +00:00
Lang Hames
44eb111f3c [ORC] Refactor definition-generation, add a generator for static libraries.
This patch replaces the JITDylib::DefinitionGenerator typedef with a class of
the same name, and adds support for attaching a sequence of DefinitionGeneration
objects to a JITDylib.

This patch also adds a new definition generator,
StaticLibraryDefinitionGenerator, that can be used to add symbols fom a static
library to a JITDylib. An object from the static library will be added (via
a supplied ObjectLayer reference) whenever a symbol from that object is
referenced.

To enable testing, lli is updated to add support for the --extra-archive option
when running in -jit-kind=orc-lazy mode.

llvm-svn: 368707
2019-08-13 16:05:18 +00:00
Jordan Rupprecht
3abe0b3ab9 [llvm-readelf] Implement note parsing for NT_FILE and unknown descriptors
Summary:
This patch implements two note parsers; one for NT_FILE coredumps, e.g.:

```
  CORE                  0x00000080      NT_FILE (mapped files)
    Page size: 4096
                 Start                 End         Page Offset
    0x0000000000001000  0x0000000000002000  0x0000000000003000
        /path/to/a.out
    0x0000000000004000  0x0000000000005000  0x0000000000006000
        /path/to/libc.so
    0x0000000000007000  0x0000000000008000  0x0000000000009000
        [stack]
```

(A more realistic example can be tested locally by creating a crashing program and running `llvm-readelf -n core`)

And also implements a raw hex dump for unknown descriptor data for unhandled descriptor types.

Reviewers: MaskRay, jhenderson, grimar, alexshap

Reviewed By: MaskRay, grimar

Subscribers: emaste, llvm-commits, labath

Tags: #llvm

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

llvm-svn: 368698
2019-08-13 14:38:45 +00:00
Simon Pilgrim
68d1415581 Fix -Wdocumentation warning (@returns used in void function). NFCI.
llvm-svn: 368693
2019-08-13 13:55:38 +00:00
George Rimar
cb83c675d9 [llvm-readobj] - Remove 'error(Error EC)' helper.
We do not need it. I replaced it with
reportError(StringRef Input, Error Err).

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

llvm-svn: 368677
2019-08-13 12:07:41 +00:00
Jordan Rupprecht
31f94d2127 [llvm-ar][NFC] Fix buildbot
llvm-svn: 368578
2019-08-12 14:21:51 +00:00
Jordan Rupprecht
0d351d4f7c [llvm-readobj] Downgrade 'PT_DYNAMIC segment offset + size exceeds the size of the file' from an error to a warning
Summary: This allows llvm-readobj to print other useful information for truncated files instead of giving up.

Reviewers: jhenderson, grimar, MaskRay

Reviewed By: jhenderson, grimar, MaskRay

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 368576
2019-08-12 14:05:37 +00:00
Owen Reynolds
dc9ffeae80 [llvm-ar] Accept file paths with windows format slashes
The internal representation of llvm-ar archives uses linux style slashes
for paths, no matter the OS. In the case of windows this meant file
paths input intending to match existing members would only match if
linux style slashes where used. This change allows either slash
direction to be input by the user.

This change includes removing an unnecessary call to normalisePath and
moving the call of another.

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

llvm-svn: 368573
2019-08-12 14:00:28 +00:00
James Henderson
14a24c9e03 [llvm-readelf]Print filename for multiple inputs and fix formatting regression
This patch addresses two closely related bugs:
https://bugs.llvm.org/show_bug.cgi?id=42930 and
https://bugs.llvm.org/show_bug.cgi?id=42931.

GNU readelf prints the file name for every input unless there is only
one input and that input is not an archive. This patch adds the printing
for multiple inputs. A previous change did it for archives, but
introduced a regression with GNU compatibility for single-output
formatting, resulting in a spurious initial blank line. This is fixed in
this patch too.

Reviewed by: grimar, MaskRay

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

llvm-svn: 368435
2019-08-09 12:30:08 +00:00
Andrea Di Biagio
9bbf3a5aeb [MCA] Add flag -show-encoding to llvm-mca.
Flag -show-encoding enables the printing of instruction encodings as part of the
the instruction info view.

Example (with flags -mtriple=x86_64--  -mcpu=btver2):

Instruction Info:
[1]: #uOps
[2]: Latency
[3]: RThroughput
[4]: MayLoad
[5]: MayStore
[6]: HasSideEffects (U)
[7]: Encoding Size

[1]    [2]    [3]    [4]    [5]    [6]    [7]    Encodings:     Instructions:
 1      2     1.00                         4     c5 f0 59 d0    vmulps   %xmm0, %xmm1, %xmm2
 1      4     1.00                         4     c5 eb 7c da    vhaddps  %xmm2, %xmm2, %xmm3
 1      4     1.00                         4     c5 e3 7c e3    vhaddps  %xmm3, %xmm3, %xmm4

In this example, column Encoding Size is the size in bytes of the instruction
encoding. Column Encodings reports the actual instruction encodings as byte
sequences in hex (objdump style).

The computation of encodings is done by a utility class named mca::CodeEmitter.

In future, I plan to expose the CodeEmitter to the instruction builder, so that
information about instruction encoding sizes can be used by the simulator. That
would be a first step towards simulating the throughput from the decoders in the
hardware frontend.

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

llvm-svn: 368432
2019-08-09 11:26:27 +00:00
George Rimar
8921d6b9ca [llvm-readobj] - Remove error(llvm::Expected<T> &&E)
This is a bit strange method. It works like a unwrapOrError,
but named error. It does not report an Input name.
I removed it.

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

llvm-svn: 368430
2019-08-09 11:03:21 +00:00