Index: test/tools/llvm-objcopy/localize-hidden.test =================================================================== --- test/tools/llvm-objcopy/localize-hidden.test +++ test/tools/llvm-objcopy/localize-hidden.test @@ -55,6 +55,12 @@ Value: 0x2006 Size: 2 Visibility: STV_HIDDEN + - Name: hiddenGlobalCommon + Type: STT_OBJECT + Index: SHN_COMMON + Value: 0x2006 + Size: 2 + Visibility: STV_HIDDEN - Name: undefGlobal Type: STT_FUNC Size: 8 @@ -142,6 +148,17 @@ #CHECK-NEXT: Section: .text #CHECK-NEXT: } #CHECK-NEXT: Symbol { +#CHECK-NEXT: Name: hiddenGlobalCommon +#CHECK-NEXT: Value: 0x2006 +#CHECK-NEXT: Size: 2 +#CHECK-NEXT: Binding: Global +#CHECK-NEXT: Type: Object +#CHECK-NEXT: Other [ +#CHECK-NEXT: STV_HIDDEN +#CHECK-NEXT: ] +#CHECK-NEXT: Section: Common +#CHECK-NEXT: } +#CHECK-NEXT: Symbol { #CHECK-NEXT: Name: undefGlobal #CHECK-NEXT: Value: 0x0 #CHECK-NEXT: Size: 8 Index: test/tools/llvm-objcopy/localize.test =================================================================== --- test/tools/llvm-objcopy/localize.test +++ test/tools/llvm-objcopy/localize.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s > %t -# RUN: llvm-objcopy --localize-symbol Global -L Local -L Weak %t %t2 +# RUN: llvm-objcopy --localize-symbol Global -L Local -L Weak -L GlobalCommon %t %t2 # RUN: llvm-readobj -symbols %t2 | FileCheck %s !ELF @@ -40,6 +40,11 @@ Size: 8 Section: .text Value: 0x1010 + - Name: GlobalCommon + Type: STT_OBJECT + Index: SHN_COMMON + Value: 0x2006 + Size: 2 #CHECK: Symbols [ #CHECK-NEXT: Symbol { @@ -78,4 +83,13 @@ #CHECK-NEXT: Other: 0 #CHECK-NEXT: Section: .text #CHECK-NEXT: } +#CHECK-NEXT: Symbol { +#CHECK-NEXT: Name: GlobalCommon +#CHECK-NEXT: Value: 0x2006 +#CHECK-NEXT: Size: 2 +#CHECK-NEXT: Binding: Global +#CHECK-NEXT: Type: Object +#CHECK-NEXT: Other: 0 +#CHECK-NEXT: Section: Common +#CHECK-NEXT: } #CHECK-NEXT:] Index: tools/llvm-objcopy/llvm-objcopy.cpp =================================================================== --- tools/llvm-objcopy/llvm-objcopy.cpp +++ tools/llvm-objcopy/llvm-objcopy.cpp @@ -256,10 +256,11 @@ // them. if (Obj.SymbolTable) { Obj.SymbolTable->updateSymbols([&](Symbol &Sym) { - if ((Config.LocalizeHidden && - (Sym.Visibility == STV_HIDDEN || Sym.Visibility == STV_INTERNAL)) || - (!Config.SymbolsToLocalize.empty() && - is_contained(Config.SymbolsToLocalize, Sym.Name))) + if (Sym.getShndx() != SHN_COMMON && + ((Config.LocalizeHidden && + (Sym.Visibility == STV_HIDDEN || Sym.Visibility == STV_INTERNAL)) || + (!Config.SymbolsToLocalize.empty() && + is_contained(Config.SymbolsToLocalize, Sym.Name)))) Sym.Binding = STB_LOCAL; // Note: these two globalize flags have very similar names but different