[llvm] [SPARC][Utilities] Add names for SPARC ELF flags in LLVM binary utilities (PR #102843)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 01:59:08 PDT 2024


================
@@ -0,0 +1,57 @@
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS32" -DMACHINE_NAME="EM_SPARC" -DFLAG_NAME=""
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V8 -DFLAG_VALUE=0x0
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x0 -DREADELF_FLAG_NAME=""
+
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS32" -DMACHINE_NAME="EM_SPARC32PLUS" -DFLAG_NAME="EF_SPARC_32PLUS"
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V8PLUS-PLAIN -DFLAG_NAME=EF_SPARC_32PLUS -DFLAG_VALUE=0x100
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x100 -DREADELF_FLAG_NAME=", V8+ ABI"
+
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS32" -DMACHINE_NAME="EM_SPARC32PLUS" -DFLAG_NAME="EF_SPARC_32PLUS, EF_SPARC_SUN_US1"
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V8PLUS-US1 -DFLAG0_NAME=EF_SPARC_32PLUS -DFLAG1_NAME=EF_SPARC_SUN_US1 -DFLAG_VALUE=0x300
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x300 -DREADELF_FLAG_NAME=", V8+ ABI, Sun UltraSPARC I extensions"
+
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS64" -DMACHINE_NAME="EM_SPARCV9" -DFLAG_NAME=""
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V9-PLAIN -DFLAG_VALUE=0x0
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x0 -DREADELF_FLAG_NAME=""
+
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS64" -DMACHINE_NAME="EM_SPARCV9" -DFLAG_NAME="EF_SPARC_SUN_US1"
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V9-US1 -DFLAG_NAME=EF_SPARC_SUN_US1 -DFLAG_VALUE=0x200
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x200 -DREADELF_FLAG_NAME=", Sun UltraSPARC I extensions"
+
+# RUN: yaml2obj %s -o %t -DCLASS_NAME="ELFCLASS64" -DMACHINE_NAME="EM_SPARCV9" -DFLAG_NAME="EF_SPARC_SUN_US1, EF_SPARCV9_RMO"
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=V9-US1-RMO -DFLAG0_NAME=EF_SPARCV9_RMO -DFLAG1_NAME=EF_SPARC_SUN_US1 -DFLAG_VALUE=0x202
+# RUN: llvm-readelf -h %t | FileCheck %s --check-prefix=READELF -DFLAG_VALUE=0x202 -DREADELF_FLAG_NAME=", Sun UltraSPARC I extensions, Relaxed Memory Ordering"
+
+--- !ELF
+FileHeader:
+  Class:           [[CLASS_NAME]]
+  Data:            ELFDATA2MSB
+  Type:            ET_REL
+  Machine:         [[MACHINE_NAME]]
+  Flags:           [ [[FLAG_NAME]] ]
+
+# V8:          Flags [ ([[FLAG_VALUE]])
+# V8-NEXT:     ]
+
+# V8PLUS-PLAIN:          Flags [ ([[FLAG_VALUE]])
+# V8PLUS-PLAIN-NEXT:       [[FLAG_NAME]] ([[FLAG_VALUE]])
+# V8PLUS-PLAIN-NEXT:     ]
+
+# V8PLUS-US1:          Flags [ ([[FLAG_VALUE]])
+# V8PLUS-US1-NEXT:       [[FLAG0_NAME]]
+# V8PLUS-US1-NEXT:       [[FLAG1_NAME]]
+# V8PLUS-US1-NEXT:     ]
+
+# V9-PLAIN:          Flags [ ([[FLAG_VALUE]])
+# V9-PLAIN-NEXT:     ]
+
+# V9-US1:          Flags [ ([[FLAG_VALUE]])
+# V9-US1-NEXT:       [[FLAG_NAME]]
+# V9-US1-NEXT:     ]
+
+# V9-US1-RMO:          Flags [ ([[FLAG_VALUE]])
+# V9-US1-RMO-NEXT:       [[FLAG0_NAME]]
+# V9-US1-RMO-NEXT:       [[FLAG1_NAME]]
+# V9-US1-RMO-NEXT:     ]
----------------
jh7370 wrote:

There's an awful lot of duplication here. I feel like it could be dramatically simplified with something like the following:
```
# LLVM-COMMON:      Flags [ ([[FLAG_VALUE]])
# LLVM-FLAG1-NEXT:    [[FLAG0_NAME]]
# LLVM-FLAG2-NEXT:    [[FLAG1_NAME]]
# LLVM-COMMON-NEXT: ]
```
You'd then in your FileCheck lines use --check-prefixes to specify the set of prefixes that apply, i.e. for no flags it'd be `--check-prefixes=LLVM-COMMON`, for the single flag it'd be `--check-prefixes=LLVM-COMMON,LLVM-FLAG1` and for the two flags it'd be `--check-prefixes=LLVM-COMMON,LLVM-FLAG1,LLVM-FLAG2`. (I've used `LLVM-` as a prefix to all of these to distinguish from GNU, see comment below).

https://github.com/llvm/llvm-project/pull/102843


More information about the llvm-commits mailing list