This is an archive of the discontinued LLVM Phabricator instance.

[lld] [ELF] Print a better error for an archive containing a non-ELF file.
ClosedPublic

Authored by efriedma on Mar 8 2019, 5:26 PM.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

efriedma created this revision.Mar 8 2019, 5:26 PM
Herald added a project: Restricted Project. · View Herald Transcript
grimar added a subscriber: grimar.Mar 11 2019, 3:11 AM

I am not fond of adding the precompiled binaries to inputs.
Is it possible to use echo to create such an archive?
Or maybe you could use llvm-ar + empty file maybe (or something like that)?

ruiu added inline comments.Mar 11 2019, 8:39 AM
test/ELF/invalid/invalid-elf.test
7

As George pointed out, I think it is better to avoid checking in an .ar file, even though the file does not contain any non-ASCII byte as it is header-only file. You could easily avoid it by creating a new archive file using llvm-ar.

ruiu added inline comments.Mar 11 2019, 8:43 AM
ELF/InputFiles.cpp
1197

Maybe "not an ELF file" is a better error message as it is more consistent with other error messages below?

efriedma updated this revision to Diff 190192.Mar 11 2019, 5:54 PM

Rebased. Changed error message. Changed test to build archive with llvm-ar.

ruiu added inline comments.Mar 11 2019, 5:57 PM
ELF/InputFiles.cpp
1198

Perhaps this is a bit too complicated for this tiny utility function? I'd add "corrupted ELF file: " to the beginning of each existing error message instead.

efriedma updated this revision to Diff 190193.Mar 11 2019, 6:04 PM

Addressed review comment.

ruiu accepted this revision.Mar 11 2019, 6:07 PM

LGTM

This revision is now accepted and ready to land.Mar 11 2019, 6:07 PM
This revision was automatically updated to reflect the committed changes.
phosek added a subscriber: phosek.Mar 11 2019, 7:08 PM

This seems to be failing on our Mac bots for some reason:

-- Testing: 2004 tests, 24 threads --
Testing: 0 .. 10.. 20.. 30.. 40
FAIL: lld :: ELF/invalid/invalid-elf.test (852 of 2004)
******************** TEST 'lld :: ELF/invalid/invalid-elf.test' FAILED ********************
Script:
--
: 'RUN: at line 2';   rm -rf /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp && mkdir -p /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp
: 'RUN: at line 3';   /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/llvm-mc /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/simple.o -filetype=obj -triple x86_64-pc-linux
: 'RUN: at line 4';   echo > /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/empty.o
: 'RUN: at line 5';   llvm-ar cr /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/not-elf.a /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/empty.o
: 'RUN: at line 7';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/simple.o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/not-elf.a -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=NOT-ELF /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
: 'RUN: at line 11';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/simple.o /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/Inputs/data-encoding.a -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=INVALID-DATA-ENC /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
: 'RUN: at line 15';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp/simple.o /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/Inputs/file-class.a -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=INVALID-FILE-CLASS /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
: 'RUN: at line 19';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/Inputs/binding.elf -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=INVALID-BINDING /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
: 'RUN: at line 23';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/Inputs/section-index.elf -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
: 'RUN: at line 27';   not /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/ld.lld /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/Inputs/multiple-eh-relocs.elf -o /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/tools/lld/test/ELF/invalid/Output/invalid-elf.test.tmp2 2>&1 |    /b/s/w/ir/k/recipe_cleanup/clangWrfRL9/llvm_build_dir/bin/FileCheck --check-prefix=INVALID-EH-RELOCS /b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test
--
Exit Code: 1

Command Output (stderr):
--
/b/s/w/ir/k/llvm-project/lld/test/ELF/invalid/invalid-elf.test:9:12: error: NOT-ELF: expected string not found in input
# NOT-ELF: not-elf.a(empty.o): not an ELF file
           ^
<stdin>:1:1: note: scanning from here
ld.lld: error: undefined symbol: foo
^
<stdin>:1:17: note: possible intended match here
ld.lld: error: undefined symbol: foo
                ^

--

********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Testing Time: 21.57s
********************
Failing Tests (1):
    lld :: ELF/invalid/invalid-elf.test

  Expected Passes    : 1735
  Unsupported Tests  : 268
  Unexpected Failures: 1
[451/523] Building CXX object unittests/Transforms/Vectorize/CMakeFiles/VectorizeTests.dir/VPlanPredicatorTest.cpp.o
FAILED: tools/lld/test/CMakeFiles/check-lld

The full log is here: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8919231700097735408/+/steps/clang/0/steps/test/0/stdout

Buildbot failure should be fixed by r355894.