[all-commits] [llvm/llvm-project] 282285: [ELF] Correct error message when OUTPUT_FORMAT is ...

Shoaib Meenai via All-commits all-commits at lists.llvm.org
Thu Mar 12 22:55:10 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 2822852ffc4649b09670e6f287871990536e3c7b
      https://github.com/llvm/llvm-project/commit/2822852ffc4649b09670e6f287871990536e3c7b
  Author: Shoaib Meenai <smeenai at fb.com>
  Date:   2020-03-12 (Thu, 12 Mar 2020)

  Changed paths:
    M lld/ELF/Config.h
    M lld/ELF/InputFiles.cpp
    M lld/ELF/ScriptParser.cpp
    M lld/test/ELF/incompatible.s

  Log Message:
  -----------
  [ELF] Correct error message when OUTPUT_FORMAT is used

Any OUTPUT_FORMAT in a linker script overrides the emulation passed on
the command line, so record the passed bfdname and use that in the error
message about incompatible input files.

This prevents confusing error messages. For example, if you explicitly
pass `-m elf_x86_64` to LLD but accidentally include a linker script
which sets `OUTPUT_FORMAT(elf32-i386)`, LLD would previously complain
about your input files being compatible with elf_x86_64, which isn't the
actual issue, and is confusing because the input files are in fact
x86-64 ELF files.

Interestingly enough, this also prevents a segfault! When we don't pass
`-m` and we have an object file which is incompatible with the
`OUTPUT_FORMAT` set by a linker script, the object file is checked for
compatibility before it's added to the objectFiles vector.
config->emulation, objectFiles, and sharedFiles will all be empty, so
we'll attempt to access bitcodeFiles[0], but bitcodeFiles is also empty,
so we'll segfault. This commit prevents the segfault by adding
OUTPUT_FORMAT as a possible source of machine configuration, and it also
adds an llvm_unreachable to diagnose similar issues in the future.

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




More information about the All-commits mailing list