From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 9FB463858436 for ; Tue, 27 Dec 2022 19:47:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FB463858436 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42e.google.com with SMTP id 6so6721207pfz.4 for ; Tue, 27 Dec 2022 11:47:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=AEf0YB3Ln3k0jWPZ00bR7lFOzs+GqnlyC/gPo5a82Mg=; b=SA5MQdj1+0CaT9WQKt0OlgubzKugw9/bZ0NDlBmXTNkwRYPVjVf57slPiD93sc1vC4 /VU0OqBmFl1y7BNcr8zAEpV4sD/baAUl/CcXRIocv124psV2KHow5MWeNmIAJlu0hWlE N6vwYf9lVQiiI5uDLOTWBzQI6AJMvxDl+aTfapVEsPNZLxIlBJA3YdP9IFA3usyy8VGG rsTaWl/JmIgOFdfR+l5aSblIXsP/Y0fRFo2m4Btujy6EvatjvsjFo+EYmM/punS5ug3s IsH0b4pc6eUKGbihW2FkWD5nkFp0mGLMsntmko/i+HpZddGTb3XDxJnUPAYBDJqmfxvY 9D/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AEf0YB3Ln3k0jWPZ00bR7lFOzs+GqnlyC/gPo5a82Mg=; b=4HCZmVUkYHlawwC6IgtsTd+C2e0lYHWSDcobxnb4m9ggW/7fDlcPQsVNWwjgphzMko X0p+t/X8B31EnXoMCPB727lsnKO+gmsipvDWQzu94OzkTXETRDUpxkd76TWrDqtHW/M0 l36/lQna5FLuldSxml5wxUSBHinKbMsWMmQYRLd5q8yNd+IJnds2M22NcYwJhPKKKxV2 MCoFdVo4pogaJiLqAnsDyzaOElvwQdKn/GlpGY4A1jhWnaLidWFIJWxOSs/0BNtUsd/p W4z/26BQSoat0CwjzJjD5JErIOIG2Rde8KId9UTMlNcV/rA1hcwK8A5pBVSSVz1Dhalc savQ== X-Gm-Message-State: AFqh2kpMZYM85D1fuDnicnqnvaJ8yhTLge254aqhTjMXkrIXiyikneEk mm+ZLdRwELitrh7aHMYRUpP8zPJIrRI= X-Google-Smtp-Source: AMrXdXu0WPix/NlOlNZ/d2TEIe1gZ9258lja/YoBZ+FBo409GTjLjMdRsjMCIhYncVf6Ci2qLDM31g== X-Received: by 2002:a05:6a00:be2:b0:56b:fa67:1f7f with SMTP id x34-20020a056a000be200b0056bfa671f7fmr23978746pfu.19.1672170478469; Tue, 27 Dec 2022 11:47:58 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.30.207]) by smtp.gmail.com with ESMTPSA id z126-20020a623384000000b00576ee69c130sm8918147pfz.4.2022.12.27.11.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 11:47:57 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 84884740080 for ; Tue, 27 Dec 2022 11:47:56 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] x86-64: Allocate input section memory if needed Date: Tue, 27 Dec 2022 11:47:56 -0800 Message-Id: <20221227194756.448332-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3023.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,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: When --no-keep-memory is used, the input section memory may not be cached. Allocate input section memory for -z pack-relative-relocs if needed. bfd/ PR ld/29939 * elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Allocate input section memory if needed. ld/ PR ld/29939 * testsuite/ld-elf/dt-relr-2i.d: New test. --- bfd/elfxx-x86.c | 25 +++++++++++++++++++++++-- ld/testsuite/ld-elf/dt-relr-2i.d | 17 +++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/dt-relr-2i.d diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index 2ddca340473..ec86e75eba9 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -1541,12 +1541,33 @@ elf_x86_size_or_finish_relative_reloc } else { + bfd_byte *contents; + if (rel.r_offset >= sec->size) abort (); + + if (elf_section_data (sec)->this_hdr.contents + != NULL) + contents + = elf_section_data (sec)->this_hdr.contents; + else + { + if (!bfd_malloc_and_get_section (sec->owner, + sec, + &contents)) + info->callbacks->einfo + /* xgettext:c-format */ + (_("%F%P: %pB: failed to allocate memory for section `%pA'\n"), + info->output_bfd, sec); + + /* Cache the section contents for + elf_link_input_bfd. */ + elf_section_data (sec)->this_hdr.contents + = contents; + } htab->elf_write_addend (info->output_bfd, outrel->r_addend, - (elf_section_data (sec)->this_hdr.contents - + rel.r_offset)); + contents + rel.r_offset); } } } diff --git a/ld/testsuite/ld-elf/dt-relr-2i.d b/ld/testsuite/ld-elf/dt-relr-2i.d new file mode 100644 index 00000000000..ed0ef9ccded --- /dev/null +++ b/ld/testsuite/ld-elf/dt-relr-2i.d @@ -0,0 +1,17 @@ +#source: dt-relr-2.s +#ld: -e _start -pie --no-keep-memory $DT_RELR_LDFLAGS +#readelf: -rW -d +#target: [supports_dt_relr] + +#... + 0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+ + 0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\) + 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\) +#... +Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry: +#... +[0-9a-f]+ +[0-9a-f]+ +R_.*_(RELATIVE|UADDR.*) .* +#... +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + 4 offsets +#pass -- 2.38.1