[PATCH] D34752: [LLD][ELF] Fix nullptr dereference when creating an error message.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 3 08:24:01 PDT 2017
Awesome test!
LGTM.
Do you have commit access?
Cheers,
Rafael
Sean Eveson via Phabricator <reviews at reviews.llvm.org> writes:
> seaneveson updated this revision to Diff 105052.
> seaneveson added a comment.
>
> - Added a test
> - Fixed a missing brace in the error message string
>
>
> https://reviews.llvm.org/D34752
>
> Files:
> ELF/InputSection.cpp
> test/ELF/duplicated-synthetic-sym.s
>
>
> Index: test/ELF/duplicated-synthetic-sym.s
> ===================================================================
> --- test/ELF/duplicated-synthetic-sym.s
> +++ test/ELF/duplicated-synthetic-sym.s
> @@ -0,0 +1,10 @@
> +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> +// RUN: cd %S
> +// RUN: not ld.lld %t.o --format=binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s
> +
> +// CHECK: duplicate symbol: _binary_duplicated_synthetic_sym_s_start
> +// CHECK: defined at (internal):(.data+0x0)
> +
> + .globl _binary_duplicated_synthetic_sym_s_start
> +_binary_duplicated_synthetic_sym_s_start:
> + .long 0
> Index: ELF/InputSection.cpp
> ===================================================================
> --- ELF/InputSection.cpp
> +++ ELF/InputSection.cpp
> @@ -276,7 +276,9 @@
> template <class ELFT> std::string InputSectionBase::getObjMsg(uint64_t Off) {
> // Synthetic sections don't have input files.
> elf::ObjectFile<ELFT> *File = getFile<ELFT>();
> - std::string Filename = File ? File->getName() : "(internal)";
> + if (!File)
> + return ("(internal):(" + Name + "+0x" + utohexstr(Off) + ")").str();
> + std::string Filename = File->getName();
>
> std::string Archive;
> if (!File->ArchiveName.empty())
>
>
> Index: test/ELF/duplicated-synthetic-sym.s
> ===================================================================
> --- test/ELF/duplicated-synthetic-sym.s
> +++ test/ELF/duplicated-synthetic-sym.s
> @@ -0,0 +1,10 @@
> +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> +// RUN: cd %S
> +// RUN: not ld.lld %t.o --format=binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s
> +
> +// CHECK: duplicate symbol: _binary_duplicated_synthetic_sym_s_start
> +// CHECK: defined at (internal):(.data+0x0)
> +
> + .globl _binary_duplicated_synthetic_sym_s_start
> +_binary_duplicated_synthetic_sym_s_start:
> + .long 0
> Index: ELF/InputSection.cpp
> ===================================================================
> --- ELF/InputSection.cpp
> +++ ELF/InputSection.cpp
> @@ -276,7 +276,9 @@
> template <class ELFT> std::string InputSectionBase::getObjMsg(uint64_t Off) {
> // Synthetic sections don't have input files.
> elf::ObjectFile<ELFT> *File = getFile<ELFT>();
> - std::string Filename = File ? File->getName() : "(internal)";
> + if (!File)
> + return ("(internal):(" + Name + "+0x" + utohexstr(Off) + ")").str();
> + std::string Filename = File->getName();
>
> std::string Archive;
> if (!File->ArchiveName.empty())
More information about the llvm-commits
mailing list