Index: llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test +++ llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test @@ -1,27 +1,30 @@ -# Show that the value field is omitted if a symbol has no name or value, but is -# printed if one is present. Test for both static and dynamic relocation -# printing. +## Show that the value field is omitted when a relocation does not reference a symbol. +## In other cases, particularly when a symbol has a zero value or when it has an empty +## name, we print it. Test for both static and dynamic relocation printing. # RUN: yaml2obj %s -o %t # RUN: llvm-readelf --relocations --dyn-relocations %t | FileCheck %s -# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 3 entries: +# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 4 entries: # CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend # CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1 # CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1 # CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456 +# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 2 -# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 3 entries: +# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 4 entries: # CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend # CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1 # CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1 # CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456 +# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 2 -# CHECK: 'RELA' relocation section at offset {{.*}} contains 72 bytes: +# CHECK: 'RELA' relocation section at offset {{.*}} contains 96 bytes: # CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend # CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1 # CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1 # CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456 +# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 2 --- !ELF FileHeader: @@ -49,6 +52,11 @@ Type: R_X86_64_NONE Addend: 0x456 Symbol: 2 +## References a symbol with a zero value and an empty name. + - Offset: 0 + Type: R_X86_64_NONE + Addend: 2 + Symbol: 3 - Name: .dynamic Type: SHT_DYNAMIC Flags: [SHF_ALLOC] @@ -58,7 +66,7 @@ - Tag: DT_RELA Value: 0x1100 - Tag: DT_RELASZ - Value: 72 + Value: 96 - Tag: DT_RELAENT Value: 24 - Tag: DT_NULL @@ -81,6 +89,11 @@ Type: R_X86_64_NONE Addend: 0x456 Symbol: 2 +## References a symbol with a zero value and an empty name. + - Offset: 0 + Type: R_X86_64_NONE + Addend: 2 + Symbol: 3 Symbols: - Name: sym Value: 0 @@ -89,6 +102,9 @@ - Value: 0x123 Section: .text Binding: STB_GLOBAL + - Value: 0x0 + Section: .text + Binding: STB_GLOBAL DynamicSymbols: - Name: sym Value: 0 @@ -97,6 +113,9 @@ - Value: 0x123 Section: .text Binding: STB_GLOBAL + - Value: 0x0 + Section: .text + Binding: STB_GLOBAL ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3515,7 +3515,7 @@ Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); Fields[2].Str = RelocName.c_str(); - if (Sym && (!SymbolName.empty() || Sym->getValue() != 0)) + if (Sym) Fields[3].Str = to_string(format_hex_no_prefix(Sym->getValue(), Width)); Fields[4].Str = std::string(SymbolName); @@ -4308,7 +4308,7 @@ if (!ErrOrName) return WarnAndReturn(Sym, toString(ErrOrName.takeError())); - return {Sym, maybeDemangle(*ErrOrName)}; + return {Sym == FirstSym ? nullptr : Sym, maybeDemangle(*ErrOrName)}; } } // namespace