From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by sourceware.org (Postfix) with ESMTPS id B5B053857C42 for ; Tue, 15 Sep 2020 01:03:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B5B053857C42 IronPort-SDR: n8JhKngXz0vNi74XlP46QPpdgsRh2x2aVgPMTU3atZPX0rOt+EvEcGARhDLIty8v53eCthTnLs uANDNKiXIg5dFhgwKOLy9lupvfizF8EJgUG7YfBWEm2oWTy/ZBMd9vPX+s2zMaNtxe3nKMA7Bj AeoZREJoYdg+srWmuQi9E+9e1YQA5vblJ+I919s3R9HV7j+fx9bFHpK9+ADPlaZ4JKkrFBiVUW 4AZKNzKLsHxQWiSgPucOzI6AXtOpNOtpQ3nynF/ORWJJ0A1QVEJaABamXqdk1KaLFstnl/vup3 390= X-IronPort-AV: E=Sophos;i="5.76,427,1592863200"; d="scan'208";a="12935777" From: Hans-Peter Nilsson To: Subject: CRIS: fix PR ld/26589, a missing NULL check in fix for PR ld/22269 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT Message-ID: <20200915010317.3CDE1203AF@pchp3.se.axis.com> Date: Tue, 15 Sep 2020 03:03:17 +0200 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Sep 2020 01:03:20 -0000 Not sure why there wasn't a NULL check in the ld/22269 patch (e01c16a8) at the time, as there was one for the corresponding patch to elf32-m68k.c (5056ba1d). Incidentally, I had missed that in 2017, as a prerequisite for the ld/22269 series, the check_relocs function finally were made "safe"! (I.e. the number of references and symbol types are final, garbage collection done, so port-specific accounting can be made sanely.) Committed. I'm going to commit this to the 2.35 branch too. The test-case covers a trivial and typical use-case. bfd: PR ld/26589 * elf32-cris.c (cris_elf_check_relocs): Add missing NULL check on argument before calling UNDEFWEAK_NO_DYNAMIC_RELOC. ld: PR ld/26589 * testsuite/ld-elf/pr26589.d, testsuite/ld-elf/locref3.s: New test. diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index 6e5a2d8..61f4b24 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -3359,7 +3359,7 @@ cris_elf_check_relocs (bfd *abfd, /* No need to do anything if we're not creating a shared object. */ if (! bfd_link_pic (info) - || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) + || (h != NULL && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) break; /* We may need to create a reloc section in the dynobj and made room diff --git a/ld/testsuite/ld-cris/locref3.s b/ld/testsuite/ld-cris/locref3.s new file mode 100644 index 0000000..7991097 --- /dev/null +++ b/ld/testsuite/ld-cris/locref3.s @@ -0,0 +1,14 @@ +; Test-case primarily from PR26589, which could have been locref3.d. +; A local (like "static") function, with all ELF decorations. +.text + .type alocalfunc,@function + .p2align 1 +alocalfunc: + nop +.Lfe1: + .size alocalfunc,.Lfe1-alocalfunc + +; Random absolute reference to the address of alocalfunc, requiring a +; runtime relocation in code that needs to be PIC/PIE. + .data + .dword alocalfunc diff --git a/ld/testsuite/ld-cris/pr26589.d b/ld/testsuite/ld-cris/pr26589.d new file mode 100644 index 0000000..aee3143 --- /dev/null +++ b/ld/testsuite/ld-cris/pr26589.d @@ -0,0 +1,16 @@ +#source: dso-1.s +#source: locref3.s +#as: --pic --no-underscore --em=criself +#ld: --shared -m crislinux +#readelf: --dyn-syms -r + +# Besides typical DSO stuff (libdso-1.d), we here have a data section +# with an absolute reloc to a local symbol. For the original +# test-case, this happened for a destructor (.dtors). + +Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 1 entry: + Offset[ ]+Info[ ]+Type[ ]+Sym\.Value Sym\. Name \+ Addend +[a-f0-9]+[ ]+0+c R_CRIS_RELATIVE[ ]+ [a-f0-9]+ + +Symbol table '\.dynsym' contains 3 entries: +#pass