[llvm] [llvm-symbolizer] Make symbolizer parse section relative syntax (PR #168524)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 00:55:55 PDT 2026
================
@@ -0,0 +1,155 @@
+## Test section-relative address syntax parsing and error handling for XCOFF.
+## This tests that the (SECTION_TYPE)(+offset) syntax produces appropriate
+## error messages for invalid inputs.
+
+## Create a simple XCOFF object for testing.
+# RUN: yaml2obj %s --docnum=1 -o %t.xcoff
+
+## Test invalid section type.
+# RUN: llvm-symbolizer --obj=%t.xcoff '(INVALID)(+0x10)' 2>&1 | \
+# RUN: FileCheck %s -DTYPE=INVALID --check-prefix=INVALID-TYPE
+
+## Test unsupported section type (BSS is not supported).
+# RUN: llvm-symbolizer --obj=%t.xcoff '(BSS)(+0x10)' 2>&1 | \
+# RUN: FileCheck %s -DTYPE=BSS --check-prefix=INVALID-TYPE
+
+## Test invalid section type containing a dash.
+# RUN: llvm-symbolizer --obj=%t.xcoff '(-)(+0x10)' 2>&1 | \
+# RUN: FileCheck %s -DTYPE=- --check-prefix=INVALID-TYPE
+
+## Test empty section type.
+# RUN: llvm-symbolizer --obj=%t.xcoff '()(+0x10)' 2>&1 | \
+# RUN: FileCheck %s -DTYPE= --check-prefix=INVALID-TYPE
+
+# INVALID-TYPE: error: '([[TYPE]])(+0x10)': unknown or unsupported section type "[[TYPE]]" in section-relative address
+
+## Test offsets that do not start with '+': missing '+', empty, negative hex,
+## negative decimal. All produce the "must start with '+'" error.
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(0x10)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=NO-PLUS -DOFFSET=0x10
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)()' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=NO-PLUS -DOFFSET=
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(-0x10)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=NO-PLUS -DOFFSET=-0x10
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(-10)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=NO-PLUS -DOFFSET=-10
+
+# NO-PLUS: error: '({{.*}})({{.*}})': section-relative offset "[[OFFSET]]" must start with '+'
+
+## Test invalid offset values: '+' followed by '-', non-hex suffix, missing
+## leading zero before 'x', non-hex character in hex literal, non-numeric.
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(+-0x10)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=INVALID-OFFSET -DOFFSET=+-0x10
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(+123abc)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=INVALID-OFFSET -DOFFSET=+123abc
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(+xabc)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=INVALID-OFFSET -DOFFSET=+xabc
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(+0xdefg)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=INVALID-OFFSET -DOFFSET=+0xdefg
+# RUN: llvm-symbolizer --obj=%t.xcoff '(TEXT)(+xyz)' 2>&1 | \
+# RUN: FileCheck %s --check-prefix=INVALID-OFFSET -DOFFSET=+xyz
+
+# INVALID-OFFSET: error: '({{.*}})({{.*}})': invalid offset "[[OFFSET]]" in section-relative address
+
+## Test that a leading-zero value is treated as octal by getAsInteger(0,...).
----------------
jh7370 wrote:
Using `getAsInteger` is an implementation detail and shouldn't be mentioned here as it could easily change, so just drop "by getAsInteger(0,...)". What is important is that the output behaviour of llvm-symbolizer remains unchanged.
https://github.com/llvm/llvm-project/pull/168524
More information about the llvm-commits
mailing list