From d9c3c1cd9d7bf5e58e4bd1ae15701c921acee3f3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 18 Jun 2018 22:32:15 +0000 Subject: [PATCH] [ELF] Uniquify --wrap list. Summary: For --wrap foo --wrap foo, bfd/gold wrap the symbol only once but LLD would rotate it twice. Reviewers: ruiu, espindola Subscribers: emaste, arichardson, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D48298 llvm-svn: 334991 --- lld/ELF/Driver.cpp | 7 +++++-- lld/test/ELF/wrap.s | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0d3e0835c984..31fda769b1e3 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1303,8 +1303,11 @@ template void LinkerDriver::link(opt::InputArgList &Args) { Symtab->scanVersionScript(); // Create wrapped symbols for -wrap option. - for (auto *Arg : Args.filtered(OPT_wrap)) - Symtab->addSymbolWrap(Arg->getValue()); + std::vector Wraps = Args.getAllArgValues(OPT_wrap); + llvm::sort(Wraps.begin(), Wraps.end()); + Wraps.erase(std::unique(Wraps.begin(), Wraps.end()), Wraps.end()); + for (StringRef Name : Wraps) + Symtab->addSymbolWrap(Name); // Do link-time optimization if given files are LLVM bitcode files. // This compiles bitcode files into real object files. diff --git a/lld/test/ELF/wrap.s b/lld/test/ELF/wrap.s index b96917b7be49..a02592e24ebd 100644 --- a/lld/test/ELF/wrap.s +++ b/lld/test/ELF/wrap.s @@ -6,6 +6,8 @@ // RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s // RUN: ld.lld -o %t3 %t %t2 --wrap foo -wrap=nosuchsym // RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s +// RUN: ld.lld -o %t3 %t %t2 --wrap foo --wrap foo -wrap=nosuchsym +// RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s // CHECK: _start: // CHECK-NEXT: movl $0x11010, %edx