From patchwork Tue Dec 27 19:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 36989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1552986wrt; Tue, 27 Dec 2022 11:48:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlWR6CPIn1jrUtwUzxWYlKwYY1ABQeZ+1bY1txDG8j5LIFkCqeOMObJ4Y9eVBLW2XxC6gL X-Received: by 2002:a17:906:dfcd:b0:7ff:7876:9c5d with SMTP id jt13-20020a170906dfcd00b007ff78769c5dmr19376140ejc.62.1672170492198; Tue, 27 Dec 2022 11:48:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672170492; cv=none; d=google.com; s=arc-20160816; b=oNMGtIEtLGfYIqtDl66qvqtCsDhUAufJ3E13jrVXGIs85Ch+UyEHDKNCvozWm2s7jO EJQosXKHbO6NyhKMXZNdqMfhlypcitl2zFhrYhuDI78Zz14CX2gvC6J6waUORjMwm4O8 CUVPI7tyn0PxQWyB2GY2UnUdPKuC2pUwxpZ0L0caBVx0s2mHQ5FzcJcVT4WCpYJ1BfDZ 2m9aK7PY9qgsDAxSu7nhEW4QeUcawyLHvGkGv2u2uxFD5pflDfh7wO+8TWoFm4dwYx8t 69uidHgzhpYzyOqcFW4JvWp5zo6Sg1T9y7fTrCCWSxSF7EVq1rjM36r9WNpdYtdqn8vP h8qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=AEf0YB3Ln3k0jWPZ00bR7lFOzs+GqnlyC/gPo5a82Mg=; b=ZjBOOPchWe85YMLD1OeEcUQrq23BKmK22ofHUvqiukM5mTTifRJOemGhYa/Md9F8Mn konWSjeMzYH4Dz3DCFEs4TFWh2DF1j+TZsCPXMYGiuTG6yC38ra+5HoA7pkVe1rhxXqM Qq93que4hI1niF+EUJR8W8qkhuSDZ5idBTXLo++6pnuX+Hymr3Joo8HnwvO9lwEGArIr HRcKgOovOJ/TWelBOipRFHckD9GJYUUdxG9j7neoGWnglfunmyuIsz94U6KCqVRpXnG0 b+uvoe0Ej1d9jaWUEQVILUV7Poa1qWOVZOrat09x0l80nnemx9bSCpsxowkhGAx9lpYF 1XOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BxJxZmrh; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 7-20020a170906328700b0079744630e4asi8929034ejw.780.2022.12.27.11.48.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 11:48:12 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BxJxZmrh; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22F803858428 for ; Tue, 27 Dec 2022 19:48:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22F803858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672170488; bh=AEf0YB3Ln3k0jWPZ00bR7lFOzs+GqnlyC/gPo5a82Mg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BxJxZmrhHKW617ge19jAcrFyRyrVqtyZC3PF0yYrlpdC3/vbjIdxeoYyVaZlI0KQD jUXUEWggv0LU4VX/gvsJ+UyatXogMbi00N8bQdX3LJzT5row2yTak3SsVSUVcC0YGD xo23XUtZW5UpyC8Pu6t8cgbC3jyCseR/IQguR4kU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-pf1-x42e.google.com with SMTP id 6so6721207pfz.4 for ; Tue, 27 Dec 2022 11:47:59 -0800 (PST) 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-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) 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 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 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-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753397845894734838?= X-GMAIL-MSGID: =?utf-8?q?1753397845894734838?= 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