Index: llvm/test/tools/llvm-objcopy/ELF/localize.test =================================================================== --- llvm/test/tools/llvm-objcopy/ELF/localize.test +++ llvm/test/tools/llvm-objcopy/ELF/localize.test @@ -1,6 +1,7 @@ # RUN: yaml2obj %s > %t # RUN: llvm-objcopy \ # RUN: --localize-symbol Global \ +# RUN: -L GlobalUndef \ # RUN: -L Local \ # RUN: -L Weak \ # RUN: -L GlobalCommon \ @@ -45,6 +46,8 @@ Size: 8 Section: .text Value: 0x1010 + - Name: GlobalUndef + Type: STT_FUNC - Name: GlobalCommon Type: STT_OBJECT Index: SHN_COMMON @@ -89,6 +92,15 @@ #CHECK-NEXT: Section: .text #CHECK-NEXT: } #CHECK-NEXT: Symbol { +#CHECK-NEXT: Name: GlobalUndef +#CHECK-NEXT: Value: +#CHECK-NEXT: Size: +#CHECK-NEXT: Binding: Global +#CHECK-NEXT: Type: Function +#CHECK-NEXT: Other: +#CHECK-NEXT: Section: Undefined +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { #CHECK-NEXT: Name: GlobalCommon #CHECK-NEXT: Value: 0x2006 #CHECK-NEXT: Size: 2 Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -282,7 +282,7 @@ // them. if (Obj.SymbolTable) { Obj.SymbolTable->updateSymbols([&](Symbol &Sym) { - if (!Sym.isCommon() && + if (!Sym.isCommon() && Sym.getShndx() != SHN_UNDEF && ((Config.LocalizeHidden && (Sym.Visibility == STV_HIDDEN || Sym.Visibility == STV_INTERNAL)) || is_contained(Config.SymbolsToLocalize, Sym.Name)))