Skip to content

Commit

Permalink
[Object] Change ELFObjectFile<ELFT>::getFileFormatName() to use BFD n…
Browse files Browse the repository at this point in the history
…ames

Follow-up for D74433

What the function returns are almost standard BFD names, except that "ELF" is
in uppercase instead of lowercase.

This patch changes "ELF" to "elf" and changes ARM/AArch64 to use their BFD names.
MIPS and PPC64 have endianness differences as well, but this patch does not intend to address them.

Advantages:

* llvm-objdump: the "file format " line matches GNU objdump on ARM/AArch64 objects
* "file format " line can be extracted and fed into llvm-objcopy -O literally.
  (ClangBuiltLinux/linux#779 has such a use case)

Affected tools: llvm-readobj, llvm-objdump, llvm-dwarfdump, MCJIT (internal implementation detail, not exposed)

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D76046
  • Loading branch information
MaskRay authored and memfrob committed Oct 4, 2022
1 parent e9a0e41 commit f867c83
Show file tree
Hide file tree
Showing 48 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion lld/test/ELF/basic-ppc.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
li 3,1
sc

// CHECK: Format: ELF32-ppc
// CHECK: Format: elf32-powerpc
// CHECK-NEXT: Arch: powerpc
// CHECK-NEXT: AddressSize: 32bit
// CHECK-NEXT: LoadName:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/basic-ppc64.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
li 3,55
sc

// CHECK:Format: ELF64-ppc64
// CHECK: Format: elf64-powerpc
// LE-NEXT: Arch: powerpc64le
// BE-NEXT: Arch: powerpc64{{$}}
// CHECK-NEXT: AddressSize: 64bit
Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/format-binary.test
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
# RUN: ld.lld -b binary %t.binary -T %t.script -o %t.out
# RUN: llvm-readobj %t.out -sections -section-data -symbols | FileCheck -check-prefix=X86-64 %s

# X86-64: Format: ELF64-x86-64
# X86-64: Format: elf64-x86-64

# RUN: echo 'OUTPUT_FORMAT("elf64-x86-64")' > %t.script
# RUN: ld.lld -b binary %t.binary -T %t.script -o %t.out
# RUN: llvm-readobj %t.out -sections -section-data -symbols | FileCheck -check-prefix=X86-64-in-quotes %s

# X86-64-in-quotes: Format: ELF64-x86-64
# X86-64-in-quotes: Format: elf64-x86-64
6 changes: 3 additions & 3 deletions lld/test/ELF/gnu-hash-table.s
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
# EMPTY-NEXT: Values: []
# EMPTY-NEXT: }

# I386: Format: ELF32-i386
# I386: Format: elf32-i386
# I386: Arch: i386
# I386: AddressSize: 32bit
# I386: Sections [
Expand Down Expand Up @@ -127,7 +127,7 @@
# I386-NEXT: Values: [0xB8860BA, 0xB887389]
# I386-NEXT: }

# X86_64: Format: ELF64-x86-64
# X86_64: Format: elf64-x86-64
# X86_64: Arch: x86_64
# X86_64: AddressSize: 64bit
# X86_64: Sections [
Expand Down Expand Up @@ -187,7 +187,7 @@
# X86_64-NEXT: Values: [0xB8860BA, 0xB887389]
# X86_64-NEXT: }

# PPC64: Format: ELF64-ppc64
# PPC64: Format: elf64-powerpc
# PPC64: Arch: powerpc64
# PPC64: AddressSize: 64bit
# PPC64: Sections [
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/linkerscript/linker-script-in-search-path.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# RUN: echo 'OUTPUT("%t.out")' > %t.dir/script
# RUN: ld.lld -T%t.dir/script %t.o
# RUN: llvm-readobj %t.out | FileCheck %s
# CHECK: Format: ELF64-x86-64
# CHECK: Format: elf64-x86-64

# If the linker script specified with -T is missing we should emit an error
# RUN: not ld.lld -Tscript %t.o 2>&1 | FileCheck %s -check-prefix ERROR
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/lto/lto-start.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; RUN: ld.lld %t.o -o %t2
; RUN: llvm-readobj --symbols %t2 | FileCheck %s

; CHECK: Format: ELF64-x86-64
; CHECK: Format: elf64-x86-64
; CHECK-NEXT: Arch: x86_64
; CHECK-NEXT: AddressSize: 64bit

Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/lto/obj-path.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
; CHECK-NEXT: T g

; NM1: T f
; ELF1: Format: ELF64-x86-64
; ELF1: Format: elf64-x86-64

; NM2: T g
; ELF2: Format: ELF64-x86-64
; ELF2: Format: elf64-x86-64

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/lto/thinlto-debug-fission.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
; RUN: ld.lld --plugin-opt=dwo_dir=%t.dir -shared %t1.o -o /dev/null
; RUN: llvm-readobj -h %t.dir/0.dwo | FileCheck %s

; CHECK: Format: ELF64-x86-64
; CHECK: Format: elf64-x86-64

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/lto/thinlto-obj-path.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
; RUN: ld.lld -thinlto-index-only -lto-obj-path=%t4.o -shared %t1.o %t2.o -o /dev/null
; RUN: llvm-readobj -h %t4.o | FileCheck %s

; CHECK: Format: ELF64-x86-64
; CHECK: Format: elf64-x86-64

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/relocatable-empty-archive.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# RUN: ld.lld -m elf_x86_64 %t.a -o %t -r
# RUN: llvm-readobj --file-headers %t | FileCheck %s

# CHECK: Format: ELF64-x86-64
# CHECK: Format: elf64-x86-64
# CHECK: Arch: x86_64
# CHECK: AddressSize: 64bit
# CHECK: Type: Relocatable
2 changes: 1 addition & 1 deletion lld/test/ELF/relocatable.s
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# CHECKTEXT-NEXT: 40: c7 04 25 00 00 00 00 08 00 00 00 movl $8, 0
# CHECKTEXT-NEXT: 4b: c7 04 25 00 00 00 00 09 00 00 00 movl $9, 0

# CHECKEXE: Format: ELF64-x86-64
# CHECKEXE: Format: elf64-x86-64
# CHECKEXE-NEXT: Arch: x86_64
# CHECKEXE-NEXT: AddressSize: 64bit
# CHECKEXE-NEXT: LoadName:
Expand Down
50 changes: 25 additions & 25 deletions llvm/include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,59 +1060,59 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
case ELF::ELFCLASS32:
switch (EF.getHeader()->e_machine) {
case ELF::EM_386:
return "ELF32-i386";
return "elf32-i386";
case ELF::EM_IAMCU:
return "ELF32-iamcu";
return "elf32-iamcu";
case ELF::EM_X86_64:
return "ELF32-x86-64";
return "elf32-x86-64";
case ELF::EM_ARM:
return (IsLittleEndian ? "ELF32-arm-little" : "ELF32-arm-big");
return (IsLittleEndian ? "elf32-littlearm" : "elf32-bigarm");
case ELF::EM_AVR:
return "ELF32-avr";
return "elf32-avr";
case ELF::EM_HEXAGON:
return "ELF32-hexagon";
return "elf32-hexagon";
case ELF::EM_LANAI:
return "ELF32-lanai";
return "elf32-lanai";
case ELF::EM_MIPS:
return "ELF32-mips";
return "elf32-mips";
case ELF::EM_MSP430:
return "ELF32-msp430";
return "elf32-msp430";
case ELF::EM_PPC:
return "ELF32-ppc";
return "elf32-powerpc";
case ELF::EM_RISCV:
return "ELF32-riscv";
return "elf32-littleriscv";
case ELF::EM_SPARC:
case ELF::EM_SPARC32PLUS:
return "ELF32-sparc";
return "elf32-sparc";
case ELF::EM_AMDGPU:
return "ELF32-amdgpu";
return "elf32-amdgpu";
default:
return "ELF32-unknown";
return "elf32-unknown";
}
case ELF::ELFCLASS64:
switch (EF.getHeader()->e_machine) {
case ELF::EM_386:
return "ELF64-i386";
return "elf64-i386";
case ELF::EM_X86_64:
return "ELF64-x86-64";
return "elf64-x86-64";
case ELF::EM_AARCH64:
return (IsLittleEndian ? "ELF64-aarch64-little" : "ELF64-aarch64-big");
return (IsLittleEndian ? "elf64-littleaarch64" : "elf64-bigaarch64");
case ELF::EM_PPC64:
return "ELF64-ppc64";
return "elf64-powerpc";
case ELF::EM_RISCV:
return "ELF64-riscv";
return "elf64-littleriscv";
case ELF::EM_S390:
return "ELF64-s390";
return "elf64-s390";
case ELF::EM_SPARCV9:
return "ELF64-sparc";
return "elf64-sparc";
case ELF::EM_MIPS:
return "ELF64-mips";
return "elf64-mips";
case ELF::EM_AMDGPU:
return "ELF64-amdgpu";
return "elf64-amdgpu";
case ELF::EM_BPF:
return "ELF64-BPF";
return "elf64-bpf";
default:
return "ELF64-unknown";
return "elf64-unknown";
}
default:
// FIXME: Proper error handling.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void RuntimeDyldELF::setMipsABI(const ObjectFile &Obj) {
IsMipsO32ABI = AbiVariant & ELF::EF_MIPS_ABI_O32;
IsMipsN32ABI = AbiVariant & ELF::EF_MIPS_ABI2;
}
IsMipsN64ABI = Obj.getFileFormatName().equals("ELF64-mips");
IsMipsN64ABI = Obj.getFileFormatName().equals("elf64-mips");
}

// Return the .TOC. section and offset.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/arm64-simplest-elf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define void @foo() nounwind {

; Similarly make sure ELF output works and is vaguely sane: aarch64 target
; machine with correct section & symbol names.
; CHECK-ELF: file format elf64-aarch64
; CHECK-ELF: file format elf64-littleaarch64

; CHECK-ELF: Disassembly of section .text
; CHECK-ELF-LABEL: <foo>:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AMDGPU/elf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; Test that we don't try to produce a COFF file on windows
; RUN: llc < %s -mtriple=amdgcn-pc-mingw -verify-machineinstrs -filetype=obj | llvm-readobj -S --symbols --file-headers - | FileCheck --check-prefix=ELF %s

; ELF: Format: ELF64-amdgpu
; ELF: Format: elf64-amdgpu
; ELF: OS/ABI: SystemV (0x0)
; ELF: Machine: EM_AMDGPU (0xE0)
; ELF: Name: .AMDGPU.config
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AMDGPU/elf.r600.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: llc < %s -march=r600 -mcpu=redwood -filetype=obj | llvm-readobj -S - | FileCheck --check-prefix=ELF %s
; RUN: llc < %s -march=r600 -mcpu=redwood -o - | FileCheck --check-prefix=CONFIG %s

; ELF: Format: ELF32-amdgpu
; ELF: Format: elf32-amdgpu
; ELF: Name: .AMDGPU.config

; CONFIG: .section .AMDGPU.config
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/AArch64/big-endian-dump.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llc -O0 -filetype=obj -mtriple=aarch64_be-none-linux < %s | llvm-dwarfdump - | FileCheck %s

; CHECK: file format ELF64-aarch64-big
; CHECK: file format elf64-bigaarch64

target datalayout = "E-m:e-i64:64-i128:128-n32:64-S128"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/AArch64/little-endian-dump.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llc -O0 -filetype=obj -mtriple=aarch64-none-linux < %s | llvm-dwarfdump - | FileCheck %s

; CHECK: file format ELF64-aarch64-little
; CHECK: file format elf64-littleaarch64

target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/ARM/big-endian-dump.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llc -O0 -filetype=obj -mtriple=armeb-none-linux < %s | llvm-dwarfdump - | FileCheck %s

; CHECK: file format ELF32-arm-big
; CHECK: file format elf32-bigarm

target datalayout = "E-m:e-p:32:32-i64:64-v128:64:128-n32-S64"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/ARM/little-endian-dump.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llc -O0 -filetype=obj -mtriple=arm-none-linux < %s | llvm-dwarfdump - | FileCheck %s

; CHECK: file format ELF32-arm-little
; CHECK: file format elf32-littlearm

target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64"

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/Sparc/gnu-window-save.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
; Check for DW_CFA_GNU_Window_save in debug_frame. Also, Ensure that relocations
; are performed correctly in debug_info.

; SPARC64: file format ELF64-sparc
; SPARC64: file format elf64-sparc

; SPARC64: .debug_info
; SPARC64: DW_TAG_compile_unit
Expand All @@ -20,7 +20,7 @@
; SPARC64-NEXT: DW_CFA_register


; SPARC32: file format ELF32-sparc
; SPARC32: file format elf32-sparc

; SPARC32: .debug_info
; SPARC32: DW_TAG_compile_unit
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/ARM/dwarf-asm-no-code.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
a:
.long 42

// DWARF: ELF32-arm-little
// DWARF: elf32-littlearm
// DWARF-NOT: contents:
// DWARF: .debug_line contents:

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/AVR/dwarf-asm-no-code.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
a:
.long 42

// DWARF: ELF32-avr
// DWARF: elf32-avr
// DWARF-NOT: contents:
// DWARF: .debug_line contents:

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/AsmParser/non-english-characters.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RUN: llvm-mc -triple i386-linux-gnu -filetype=obj -o %t \
# RUN: %S/Inputs/non-english-characters-comments.s
# RUN: llvm-readobj %t | FileCheck %s
# CHECK: Format: ELF32-i386
# CHECK: Format: elf32-i386

# RUN: not llvm-mc -triple i386-linux-gnu -filetype=obj -o %t \
# RUN: %S/Inputs/non-english-characters-section-name.s 2>&1 | \
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/ELF/empty.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Check that we can create ELF files for darwin/windows, even though
// it is not the default file format.

// DARWIN: Format: ELF64-x86-64
// WINDOWS: Format: ELF64-x86-64
// DARWIN: Format: elf64-x86-64
// WINDOWS: Format: elf64-x86-64
// DARWIN-NEXT: Arch: x86_64
// WINDOWS-NEXT: Arch: x86_64

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/ELF/relocation-386.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Test that we produce the correct relocation types and that the relocations
// correctly point to the section or the symbol.

// IAMCU: Format: ELF32-iamcu
// I386: Format: ELF32-i386
// IAMCU: Format: elf32-iamcu
// I386: Format: elf32-i386
// CHECK: Relocations [
// CHECK-NEXT: Section {{.*}} .rel.text {
// CHECK-NEXT: 0x2 R_386_GOTOFF .Lfoo 0x0
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/Hexagon/basic.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; RUN: llc -mtriple=hexagon-unknown-elf -filetype=obj %s -o - \
;; RUN: | llvm-readobj -h -r | FileCheck -check-prefix=OBJ %s

; OBJ: Format: ELF32-hexagon
; OBJ: Format: elf32-hexagon
; OBJ: Arch: hexagon
; OBJ: AddressSize: 32bit
; OBJ: Machine: EM_HEXAGON (0xA4)
4 changes: 2 additions & 2 deletions llvm/test/MC/RISCV/elf-header.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# RUN: llvm-mc %s -filetype=obj -triple=riscv64 | llvm-readobj -h \
# RUN: | FileCheck -check-prefix=RV64 %s

# RV32: Format: ELF32-riscv
# RV32: Format: elf32-littleriscv
# RV32: Arch: riscv32
# RV32: AddressSize: 32bit
# RV32: ElfHeader {
Expand All @@ -22,7 +22,7 @@
# RV32: ]
# RV32: }

# RV64: Format: ELF64-riscv
# RV64: Format: elf64-littleriscv
# RV64: Arch: riscv64
# RV64: AddressSize: 64bit
# RV64: ElfHeader {
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/Sparc/sparc-relocations.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s
! RUN: llvm-mc %s -arch=sparcv9 -filetype=obj | llvm-readobj -r | FileCheck %s --check-prefix=CHECK-OBJ

! CHECK-OBJ: Format: ELF64-sparc
! CHECK-OBJ: Format: elf64-sparc
! CHECK-OBJ: Relocations [
! CHECK-OBJ: 0x{{[0-9,A-F]+}} R_SPARC_WDISP30 foo
! CHECK-OBJ: 0x{{[0-9,A-F]+}} R_SPARC_LO10 sym
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Object/AMDGPU/elf32-unknown.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readobj -S --file-headers %t.o | FileCheck %s

# CHECK: Format: ELF32-amdgpu
# CHECK: Format: elf32-amdgpu

--- !ELF
FileHeader:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Object/AMDGPU/elf64-unknown.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readobj -S --file-headers %t.o | FileCheck %s

# CHECK: Format: ELF64-amdgpu
# CHECK: Format: elf64-amdgpu

--- !ELF
FileHeader:
Expand Down
Loading

0 comments on commit f867c83

Please sign in to comment.