]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: testsuite: Add sframe test for PR 33401
authorClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Fri, 12 Dec 2025 15:02:32 +0000 (17:02 +0200)
committerClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Fri, 12 Dec 2025 15:14:29 +0000 (17:14 +0200)
When linking for a relocable output file (-r), one or more R_*_NONE
relocations may be generated for .sframe section. Two new tcl
procedures are added to sframe.exp file. 'check-dump' is checking if
an input bin file has the same relocation as specified in the second
input argument. 'check_pr33401' is the main checking function for
PR33401 which calls twice the ld tool to produce an relocable output
file.

ld:

PR33401
* testsuite/ld-sframe/StateClient.cpp: New file.
* testsuite/ld-sframe/StatePlaying.cpp: Likewise.
* testsuite/ld-sframe/pr33401.rd: Likewise.
* testsuite/ld-sframe/sframe.exp (check_pr33401): New procedure.

Co-authored-by: Indu Bhagat <indu.bhagat@oracle.com>
Reviewed-by: Indu Bhagat <indu.bhagat@oracle.com>
ld/testsuite/ld-sframe/StateClient.cpp [new file with mode: 0644]
ld/testsuite/ld-sframe/StatePlaying.cpp [new file with mode: 0644]
ld/testsuite/ld-sframe/pr33401.rd [new file with mode: 0644]
ld/testsuite/ld-sframe/sframe.exp

diff --git a/ld/testsuite/ld-sframe/StateClient.cpp b/ld/testsuite/ld-sframe/StateClient.cpp
new file mode 100644 (file)
index 0000000..0154469
--- /dev/null
@@ -0,0 +1,26 @@
+void a(void *);
+class b {
+  long ag;
+  bool c();
+  void m_fn2() {
+    if (c())
+      d(ag);
+  }
+  void d(long);
+
+public:
+  ~b() { m_fn2(); }
+};
+class Player {
+  int *an;
+  b ao;
+  char be;
+
+public:
+  virtual ~Player() {
+    a(&be);
+    a(&be);
+    a(&be);
+    delete an;
+  }
+} e;
diff --git a/ld/testsuite/ld-sframe/StatePlaying.cpp b/ld/testsuite/ld-sframe/StatePlaying.cpp
new file mode 100644 (file)
index 0000000..f61c32d
--- /dev/null
@@ -0,0 +1,41 @@
+void b(void *);
+class c {
+public:
+  long am;
+  bool d();
+  void e() {
+    if (d())
+      f(am);
+  }
+  void f(long);
+  ~c() { e(); }
+};
+class g {
+public:
+  virtual ~g();
+};
+class Player {
+  int *bh;
+  c bi;
+  char bj;
+
+public:
+  virtual ~Player() {
+    b(&bj);
+    b(&bj);
+    b(&bj);
+    delete bh;
+  }
+};
+class h {
+public:
+  ~h() {
+    Player *a[0];
+    delete a[0];
+  }
+};
+class i : g {
+  h bo;
+  virtual int j();
+};
+int i::j() {}
diff --git a/ld/testsuite/ld-sframe/pr33401.rd b/ld/testsuite/ld-sframe/pr33401.rd
new file mode 100644 (file)
index 0000000..0014281
--- /dev/null
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ +0+ +R_.*_NONE +.*
+#pass
\ No newline at end of file
index 61dc4dafa2ec3d1b2fece48b3367da57de6a2b63..acd52a4ef1822a593eecd43eac404518e57f7506 100644 (file)
 # MA 02110-1301, USA.
 #
 
+# Test infrastructure for bug 33401
+# https://sourceware.org/bugzilla/show_bug.cgi?id=33401
+# Sframe section contains R_*_NONE relocations intermingled with other
+# relas in the output relocatable object.
+#
+proc check_pr33401 { } {
+    global CXX_FOR_TARGET
+    global ld
+    global srcdir
+    global subdir
+
+    # Check to see if C++ compiler work
+    if { [which $CXX_FOR_TARGET] == 0 } {
+       unsupported "PR ld/33401"
+       return 0
+    }
+
+    # 1. First step: Create a relocatable object (pr33401.o) from sources.
+    #     Some R_*_NONE are expected for this input.
+    set test_list {
+       { "PR ld/33401 (Step 1: Create relocatable object and check R_*_NONE)"
+           "-r"
+           "-g -O2 -w -Wa,--gsframe"
+           {StateClient.cpp StatePlaying.cpp}
+           {{readelf "-r -W" pr33401.rd}}
+           "pr33401.o"
+           "c++" }
+    }
+
+    # Run the test
+    if { [run_cc_link_tests $test_list] == 0 } {
+       verbose -log "No R_*_NONE in .rela.sframe"
+       return
+    }
+
+    # 2. Final step: Run ld -r again on the output of step 1.
+    #   The assertion failure in PR 33401 occurred when processing input BFDs
+    #   containing R_*_NONE relocations in the .sframe section.
+    set testname "PR ld/33401 (Step 2: Final link)"
+
+    # Attempt to link the object created in step 1
+    if { ![ld_link $ld /dev/null "-L$srcdir/$subdir -r tmpdir/pr33401.o"] } {
+       fail $testname
+    } else {
+       pass $testname
+    }
+}
+
 if [skip_sframe_tests] {
     unsupported "no SFrame format support in the assembler, or SFrame disabled"
     return 0
@@ -40,6 +88,8 @@ foreach sframe_test $sframe_test_list {
     run_dump_test [file rootname $sframe_test]
 }
 
+check_pr33401
+
 if {[info exists old_lc_all]} {
     set env(LC_ALL) $old_lc_all
 } else {