From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 1F5903858281 for ; Wed, 18 Jan 2023 17:32:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F5903858281 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4497E3F081 for ; Wed, 18 Jan 2023 17:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1674063144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=I+AwrCQ/5VnR6yr6CzL6JjUIWNfnvLN8ZUhMyRft64k=; b=Jga+qXp+nCSNbZaeUVCqFcLmN25Jt42m4rSs+jgurJ/ecihXP3T50TBoPWiFsRLYlaAkQi t7mgDMOKhvpg0OOl5lV/9/SS5k0cwf41HirS68lxaQPWm569gnu59RnWEQ9XR48X3AK/vP W3GoJKgmCxJx2jJpeJOYJXlWOy9govc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1674063144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=I+AwrCQ/5VnR6yr6CzL6JjUIWNfnvLN8ZUhMyRft64k=; b=+cnuUduiHgMA0akLB4r0lyRe2NOm780RRcHQVmIyrDn/3veg096VzNfdkGWlCvasNK2zwp 0+NAQ8z14lQHalDQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 406012C141 for ; Wed, 18 Jan 2023 17:32:24 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 3B31B6397; Wed, 18 Jan 2023 17:32:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 397E162E5 for ; Wed, 18 Jan 2023 17:32:24 +0000 (UTC) Date: Wed, 18 Jan 2023 17:32:24 +0000 (UTC) From: Michael Matz To: binutils@sourceware.org Subject: [PATCH 3/3] Add testcase ld-elf/merge4 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: to check a situation that once failed with the new section merging when it mishandled offsets pointing into alignment padding in mergable string sections (i.e. pointing to zeros). It made bootstrap.exp fail but that depends on many factors to actually go wrong so this is a more explicit variant of it. --- ld/testsuite/ld-elf/elf.exp | 6 ++++++ ld/testsuite/ld-elf/merge4.out | 3 +++ ld/testsuite/ld-elf/merge4a.c | 23 +++++++++++++++++++++++ ld/testsuite/ld-elf/merge4b.s | 23 +++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 ld/testsuite/ld-elf/merge4.out create mode 100644 ld/testsuite/ld-elf/merge4a.c create mode 100644 ld/testsuite/ld-elf/merge4b.s diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index a3a8994749d..1a160d084e0 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -607,4 +607,10 @@ run_ld_link_exec_tests [list \ ] \ ] +set merge_exec_tests { + {"merge4" "" "" + {merge4a.c merge4b.s} "merge4" "merge4.out"} +} +run_ld_link_exec_tests $merge_exec_tests + catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status diff --git a/ld/testsuite/ld-elf/merge4.out b/ld/testsuite/ld-elf/merge4.out new file mode 100644 index 00000000000..92c1b71f712 --- /dev/null +++ b/ld/testsuite/ld-elf/merge4.out @@ -0,0 +1,3 @@ +1: foobar +2: +3: blabla diff --git a/ld/testsuite/ld-elf/merge4a.c b/ld/testsuite/ld-elf/merge4a.c new file mode 100644 index 00000000000..133303e11ac --- /dev/null +++ b/ld/testsuite/ld-elf/merge4a.c @@ -0,0 +1,23 @@ +extern const char * getstr3(int); +extern int printf (const char *, ...); + +extern const char *addr_of_str; +extern const char *addr_of_str2; + +/* "foobar" needs to be a string literal, so that it's put into + a mergable string section, then merged with the "foobar" from merge4b.s + and then (when the linker is buggy) doesn't cover the additional + nul byte after "foobar" in the asm source (which addr_of_str2 is supposed + to point into. */ +const char * getstr3(int i) +{ + return i ? "blabla" : "foobar"; +} + +int main(void) +{ + printf ("1: %s\n", addr_of_str); + printf ("2: %s\n", addr_of_str2); + printf ("3: %s\n", getstr3(1)); + return 0; +} diff --git a/ld/testsuite/ld-elf/merge4b.s b/ld/testsuite/ld-elf/merge4b.s new file mode 100644 index 00000000000..d4b66aab5e6 --- /dev/null +++ b/ld/testsuite/ld-elf/merge4b.s @@ -0,0 +1,23 @@ +/* Check that pointing into padding zeros of string sections works. */ + .section .rodata.str1.1,"aMS",@progbits,1 + .string "" +.LC0: + .string "foobar" +1: + .string "" + .string "whatever" + .section .data + .globl addr_of_str + .type addr_of_str, @object +addr_of_str: + .dc.a str + .globl addr_of_str2 + .type addr_of_str2, @object +addr_of_str2: + .dc.a 1b + .section .rodata + .type str, @object + .size str, 7 +str: + .string "foobar" + .section .note.GNU-stack,"",@progbits -- 2.36.1