gold: Get linkonce/comdate sections for debugging sections
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 29 Nov 2020 13:55:23 +0000 (05:55 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 29 Nov 2020 13:55:35 +0000 (05:55 -0800)
When relocating debug sections, get the section index for the linkonce
section.  Since symbols referenced in debugging sections can be defined
a single comdat section with a different section name, also check the
single comdat section.

PR gold/26937
* object.cc (Sized_relobj_file::map_to_kept_section): Get the
section index for linkonce section.  Also check the single
comdat section.
* testsuite/Makefile.am (check_SCRIPTS): Add pr26936.sh.
(check_DATA): Add pr26936a.stdout and pr26936b.stdout.
(MOSTLYCLEANFILES): Add pr26936a and pr26936b.
(pr26936a.stdout): New target.
(pr26936a): Likewise.
(pr26936b.stdout): Likewise.
(pr26936b): Likewise.
(pr26936a.o): Likewise.
(pr26936b.o): Likewise.
(pr26936c.o): Likewise.
(pr26936d.o): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/pr26936.sh: New file.
* testsuite/pr26936a.s: Likewise.
* testsuite/pr26936b.s: Likewise.
* testsuite/pr26936c.s: Likewise.
* testsuite/pr26936d.s: Likewise.

gold/ChangeLog
gold/object.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/pr26936.sh [new file with mode: 0755]
gold/testsuite/pr26936a.s [new file with mode: 0644]
gold/testsuite/pr26936b.s [new file with mode: 0644]
gold/testsuite/pr26936c.s [new file with mode: 0644]
gold/testsuite/pr26936d.s [new file with mode: 0644]

index 4739ed5cd591bdd7a387025e38a1e121812bfdf3..1e90cbdda6351e9827131e010ba010aa4ed0b70d 100644 (file)
@@ -1,3 +1,27 @@
+2020-11-29  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gold/26937
+       * object.cc (Sized_relobj_file::map_to_kept_section): Get the
+       section index for linkonce section.  Also check the single
+       comdat section.
+       * testsuite/Makefile.am (check_SCRIPTS): Add pr26936.sh.
+       (check_DATA): Add pr26936a.stdout and pr26936b.stdout.
+       (MOSTLYCLEANFILES): Add pr26936a and pr26936b.
+       (pr26936a.stdout): New target.
+       (pr26936a): Likewise.
+       (pr26936b.stdout): Likewise.
+       (pr26936b): Likewise.
+       (pr26936a.o): Likewise.
+       (pr26936b.o): Likewise.
+       (pr26936c.o): Likewise.
+       (pr26936d.o): Likewise.
+       * testsuite/Makefile.in: Regenerated.
+       * testsuite/pr26936.sh: New file.
+       * testsuite/pr26936a.s: Likewise.
+       * testsuite/pr26936b.s: Likewise.
+       * testsuite/pr26936c.s: Likewise.
+       * testsuite/pr26936d.s: Likewise.
+
 2020-11-17  Alan Modra  <amodra@gmail.com>
 
        * powerpc.cc (Target_powerpc::no_tprel_opt_): Rename from tprel_opt_.
index c486a2011d5c4d5167272ca83d93cd20f90bbf3d..c0d0f0289fcbf950eaff257bc40ef373af9c41f9 100644 (file)
@@ -2981,17 +2981,20 @@ Sized_relobj_file<size, big_endian>::map_to_kept_section(
         {
          // The kept section is a linkonce section.
          if (sh_size == kept_section->linkonce_size())
-           found = true;
+           {
+             kept_shndx = kept_section->shndx();
+             found = true;
+           }
         }
       else
        {
+         uint64_t kept_size = 0;
          if (is_comdat)
            {
              // Find the corresponding kept section.
              // Since we're using this mapping for relocation processing,
              // we don't want to match sections unless they have the same
              // size.
-             uint64_t kept_size = 0;
              if (kept_section->find_comdat_section(section_name, &kept_shndx,
                                                    &kept_size))
                {
@@ -2999,9 +3002,8 @@ Sized_relobj_file<size, big_endian>::map_to_kept_section(
                    found = true;
                }
            }
-         else
+         if (!found)
            {
-             uint64_t kept_size = 0;
              if (kept_section->find_single_comdat_section(&kept_shndx,
                                                           &kept_size)
                  && sh_size == kept_size)
index 3bfba9feb64afc04a1a55e97c880e1193355ca58..ae962a817e8a52fc540b444bd298687d26b4c465 100644 (file)
@@ -4385,4 +4385,26 @@ dwp_test_2a.dwp: ../dwp dwp_test_main.dwo dwp_test_1.dwo
 dwp_test_2b.dwp: ../dwp dwp_test_1b.dwo dwp_test_2.dwo
        ../dwp -o $@ dwp_test_1b.dwo dwp_test_2.dwo
 
+check_SCRIPTS += pr26936.sh
+check_DATA += pr26936a.stdout pr26936b.stdout
+MOSTLYCLEANFILES += pr26936a pr26936b
+pr26936a.stdout: pr26936a
+       $(TEST_READELF) -wL -wR -wr $< >$@ 2>/dev/null
+pr26936a: pr26936a.o pr26936b.o pr26936c.o ../ld-new
+       ../ld-new -Ttext-segment 0x10000 -z max-page-size=0x1000 \
+               -e _start -o $@ pr26936a.o pr26936b.o pr26936c.o
+pr26936b.stdout: pr26936b
+       $(TEST_READELF) -wL -wR -wr $< >$@ 2>/dev/null
+pr26936b: pr26936d.o pr26936b.o pr26936c.o ../ld-new
+       ../ld-new -Ttext-segment 0x10000 -z max-page-size=0x1000 \
+               -e _start -o $@ pr26936d.o pr26936b.o pr26936c.o
+pr26936a.o: pr26936a.s
+       $(TEST_AS) --gen-debug -o $@ $<
+pr26936b.o: pr26936b.s
+       $(TEST_AS) --gen-debug -o $@ $<
+pr26936c.o: pr26936c.s
+       $(TEST_AS) --gen-debug -o $@ $<
+pr26936d.o: pr26936d.s
+       $(TEST_AS) --gen-debug -o $@ $<
+
 endif DEFAULT_TARGET_X86_64
index 49fd4e95a0989b2dfe9f9cc40f6018b41c005241..695eeb1f33713354b6651d0c74253dd4b2241237 100644 (file)
@@ -1126,11 +1126,13 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@        split_s390x_z1_ns split_s390x_z2_ns split_s390x_z3_ns \
 @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@        split_s390x_z4_ns split_s390x_n1_ns split_s390x_n2_ns split_s390x_r
 
-@DEFAULT_TARGET_X86_64_TRUE@am__append_116 = *.dwo *.dwp
+@DEFAULT_TARGET_X86_64_TRUE@am__append_116 = *.dwo *.dwp pr26936a \
+@DEFAULT_TARGET_X86_64_TRUE@   pr26936b
 @DEFAULT_TARGET_X86_64_TRUE@am__append_117 = dwp_test_1.sh \
-@DEFAULT_TARGET_X86_64_TRUE@   dwp_test_2.sh
+@DEFAULT_TARGET_X86_64_TRUE@   dwp_test_2.sh pr26936.sh
 @DEFAULT_TARGET_X86_64_TRUE@am__append_118 = dwp_test_1.stdout \
-@DEFAULT_TARGET_X86_64_TRUE@   dwp_test_2.stdout
+@DEFAULT_TARGET_X86_64_TRUE@   dwp_test_2.stdout pr26936a.stdout \
+@DEFAULT_TARGET_X86_64_TRUE@   pr26936b.stdout
 subdir = testsuite
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/ax_pthread.m4 \
@@ -6439,6 +6441,13 @@ dwp_test_2.sh.log: dwp_test_2.sh
        --log-file $$b.log --trs-file $$b.trs \
        $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
        "$$tst" $(AM_TESTS_FD_REDIRECT)
+pr26936.sh.log: pr26936.sh
+       @p='pr26936.sh'; \
+       b='pr26936.sh'; \
+       $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+       --log-file $$b.log --trs-file $$b.trs \
+       $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+       "$$tst" $(AM_TESTS_FD_REDIRECT)
 object_unittest.log: object_unittest$(EXEEXT)
        @p='object_unittest$(EXEEXT)'; \
        b='object_unittest'; \
@@ -10352,6 +10361,24 @@ uninstall-am:
 @DEFAULT_TARGET_X86_64_TRUE@   ../dwp -o $@ dwp_test_main.dwo dwp_test_1.dwo
 @DEFAULT_TARGET_X86_64_TRUE@dwp_test_2b.dwp: ../dwp dwp_test_1b.dwo dwp_test_2.dwo
 @DEFAULT_TARGET_X86_64_TRUE@   ../dwp -o $@ dwp_test_1b.dwo dwp_test_2.dwo
+@DEFAULT_TARGET_X86_64_TRUE@pr26936a.stdout: pr26936a
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_READELF) -wL -wR -wr $< >$@ 2>/dev/null
+@DEFAULT_TARGET_X86_64_TRUE@pr26936a: pr26936a.o pr26936b.o pr26936c.o ../ld-new
+@DEFAULT_TARGET_X86_64_TRUE@   ../ld-new -Ttext-segment 0x10000 -z max-page-size=0x1000 \
+@DEFAULT_TARGET_X86_64_TRUE@           -e _start -o $@ pr26936a.o pr26936b.o pr26936c.o
+@DEFAULT_TARGET_X86_64_TRUE@pr26936b.stdout: pr26936b
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_READELF) -wL -wR -wr $< >$@ 2>/dev/null
+@DEFAULT_TARGET_X86_64_TRUE@pr26936b: pr26936d.o pr26936b.o pr26936c.o ../ld-new
+@DEFAULT_TARGET_X86_64_TRUE@   ../ld-new -Ttext-segment 0x10000 -z max-page-size=0x1000 \
+@DEFAULT_TARGET_X86_64_TRUE@           -e _start -o $@ pr26936d.o pr26936b.o pr26936c.o
+@DEFAULT_TARGET_X86_64_TRUE@pr26936a.o: pr26936a.s
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_AS) --gen-debug -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@pr26936b.o: pr26936b.s
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_AS) --gen-debug -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@pr26936c.o: pr26936c.s
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_AS) --gen-debug -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@pr26936d.o: pr26936d.s
+@DEFAULT_TARGET_X86_64_TRUE@   $(TEST_AS) --gen-debug -o $@ $<
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/gold/testsuite/pr26936.sh b/gold/testsuite/pr26936.sh
new file mode 100755 (executable)
index 0000000..364f50f
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# pr26936.sh -- Tests for relocations in debug sections against linkonce
+# and comdat sections.
+
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+set -e
+
+check()
+{
+    number_of_occurrence=`egrep "$2" ./$1 -o| wc -l`
+    if [ $number_of_occurrence != $3 ]
+    then
+       echo "$1: \"$2\" $3: Failed"
+       status=1
+    fi
+}
+
+status=0
+check pr26936a.stdout "^pr26936a.s +6 +0x10108 +x" 1
+check pr26936a.stdout "^pr26936b.s +5 +0x10109 +x" 1
+check pr26936a.stdout "^pr26936b.s +11 +0x10108 +x" 1
+check pr26936a.stdout "^pr26936c.s +6 +0x10108 +x" 1
+check pr26936a.stdout "^ +0+10108 0+1" 3
+check pr26936a.stdout "^ +0+10109 0+1" 1
+check pr26936a.stdout "^ +0+ 0+10109 0+1010a" 1
+check pr26936a.stdout "^ +0+ 0+10108 0+10109" 1
+check pr26936b.stdout "^pr26936d.s +6 +0x10108 +x" 1
+check pr26936b.stdout "^pr26936b.s +5 +0x10109 +x" 1
+check pr26936b.stdout "^pr26936b.s +11 +0x10108 +x" 1
+check pr26936b.stdout "^pr26936c.s +6 +0x10108 +x" 1
+check pr26936b.stdout "^ +0+10108 0+1" 3
+check pr26936b.stdout "^ +0+10109 0+1" 1
+check pr26936b.stdout "^ +0+ 0+10109 0+1010a" 1
+check pr26936b.stdout "^ +0+ 0+10108 0+10109" 1
+
+exit $status
diff --git a/gold/testsuite/pr26936a.s b/gold/testsuite/pr26936a.s
new file mode 100644 (file)
index 0000000..24b90da
--- /dev/null
@@ -0,0 +1,6 @@
+       .section .gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",%progbits
+       .globl  __x86.get_pc_thunk.bx
+       .hidden __x86.get_pc_thunk.bx
+       .type   __x86.get_pc_thunk.bx, %function
+__x86.get_pc_thunk.bx:
+       .nop
diff --git a/gold/testsuite/pr26936b.s b/gold/testsuite/pr26936b.s
new file mode 100644 (file)
index 0000000..20f064d
--- /dev/null
@@ -0,0 +1,11 @@
+       .text
+       .type _start,"function"
+       .global _start
+_start:
+       .nop
+       .section .text.__x86.get_pc_thunk.bx,"axG",%progbits,__x86.get_pc_thunk.bx,comdat
+       .globl  __x86.get_pc_thunk.bx
+       .hidden __x86.get_pc_thunk.bx
+       .type   __x86.get_pc_thunk.bx, %function
+__x86.get_pc_thunk.bx:
+       .nop
diff --git a/gold/testsuite/pr26936c.s b/gold/testsuite/pr26936c.s
new file mode 100644 (file)
index 0000000..379cb71
--- /dev/null
@@ -0,0 +1,6 @@
+       .section .text.__x86.get_pc_thunk.bx,"axG",%progbits,__x86.get_pc_thunk.bx,comdat
+       .globl  __x86.get_pc_thunk.bx
+       .hidden __x86.get_pc_thunk.bx
+       .type   __x86.get_pc_thunk.bx, %function
+__x86.get_pc_thunk.bx:
+       .nop
diff --git a/gold/testsuite/pr26936d.s b/gold/testsuite/pr26936d.s
new file mode 100644 (file)
index 0000000..379cb71
--- /dev/null
@@ -0,0 +1,6 @@
+       .section .text.__x86.get_pc_thunk.bx,"axG",%progbits,__x86.get_pc_thunk.bx,comdat
+       .globl  __x86.get_pc_thunk.bx
+       .hidden __x86.get_pc_thunk.bx
+       .type   __x86.get_pc_thunk.bx, %function
+__x86.get_pc_thunk.bx:
+       .nop
This page took 0.039329 seconds and 4 git commands to generate.