From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by sourceware.org (Postfix) with ESMTPS id 50131386075F for ; Thu, 13 Oct 2022 12:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50131386075F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-357208765adso15130267b3.12 for ; Thu, 13 Oct 2022 05:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yxlSGKoNygmb6QzIxXmk+UT+0pUdnF1mrSk6Km/Gefk=; b=HD4lT3bKvzjOz/AMVqHr9ifetwek+VJRNRhf1IY9MFYOJz14PCuWXz1DA1DMw/NgSj AgFngGVscbAIPbTRDUZGLm4imRLzi1tyKs+Z8HGesLjmQd49bZZc4bWnnZDQSxOD5XkS Vzlf2uYPPMyxSse7u+8NFeIDtvQplirsc5L2FDeU2PWk7VPFGUD8sgBbqR6/D3cSrmA4 ncfNpnIQK5Cb8iEHIHdZT7qJ1ef8VHZrXbpxwqbHVMi3yPJO97Y4kqIocw/cOMJOjwJ7 +0V3W8hWv9PGRwd1akyf5onzUwwa6LFSRfO6dGx+modq3OS4RXJ/r5DlXGPTICN87DB+ zh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yxlSGKoNygmb6QzIxXmk+UT+0pUdnF1mrSk6Km/Gefk=; b=q23knITM2Hk45yLLNPN/osa86eavH98mkKzUo5LxbKxlN3BZnuzjKaTyRucg1btWib KRdlV3Ch+RiFk3QbYTVOMEt/GBm1ykfsbP5MAx4jfbbnZ4H+PZSNtvDAeOjlz2EosJFP R3OHrPpIylY2SJU3Sx3vjhGXjhUgWbSHOEPfg4zmcgNtAa1X2x6ojJeziZDsl4xkM3Nh ch+7SbzCjgkEFe7Ci+sDEVIldPRsxAXRkiucChS/SsSnHgC82cLyKzT+yd7xihUqt/Yf 1+DFupNFiQbm9tY+Xd9An0hKVY981txFvL45ojG2NgrTdD6rV6lWXnsZtf35RCUkeJ2X +euA== X-Gm-Message-State: ACrzQf3CQWI16CtWKs1Hl44QzQ2ldDY2Bpk5x5yfXl41+p8aZUy/KCnf 10fnQ5t9olTkeQMOndtrOBmRbwYLxIZ8fZAbSUXQ6zKmBaw= X-Google-Smtp-Source: AMsMyM5w7RlpW85xKRtDskzxmNhELgt1kJBzeGvsx2PcHzt6kAFhdSQyzOrYiaVfedXuugZSy/YUYFwmrsozTkHPlMg= X-Received: by 2002:a81:1908:0:b0:33c:7394:9ee1 with SMTP id 8-20020a811908000000b0033c73949ee1mr31080858ywz.408.1665662744302; Thu, 13 Oct 2022 05:05:44 -0700 (PDT) MIME-Version: 1.0 References: <20221006114628.304185-1-chigot@adacore.com> In-Reply-To: <20221006114628.304185-1-chigot@adacore.com> From: =?UTF-8?Q?Cl=C3=A9ment_Chigot?= Date: Thu, 13 Oct 2022 14:05:32 +0200 Message-ID: Subject: Re: [PATCH] RISC-V: fix linker message when relaxation deletes bytes To: binutils@sourceware.org Cc: palmer@dabbelt.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: Gentle ping Thanks, Cl=C3=A9ment On Thu, Oct 6, 2022 at 1:46 PM Cl=C3=A9ment Chigot wro= te: > > The section relaxation can delete some bytes resulting in the symbols' > value being modified. > As the linker messages retrieve a symbol information using the > outsymbols field of abfd, it must be updated as well. > > bfd/ChangeLog: > > * elfnn-riscv.c (riscv_relax_delete_bytes): Update > abfd->outsymbols. > > ld/ChangeLog: > > * testsuite/ld-riscv-elf/ld-riscv-elf.exp: New test. > * testsuite/ld-riscv-elf/undefined-align.d: New test. > * testsuite/ld-riscv-elf/undefined-align.s: New test. > --- > bfd/elfnn-riscv.c | 23 +++++++++++++++++++++ > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 1 + > ld/testsuite/ld-riscv-elf/undefined-align.d | 5 +++++ > ld/testsuite/ld-riscv-elf/undefined-align.s | 10 +++++++++ > 4 files changed, 39 insertions(+) > create mode 100644 ld/testsuite/ld-riscv-elf/undefined-align.d > create mode 100644 ld/testsuite/ld-riscv-elf/undefined-align.s > > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c > index 3d2ddf4e651..7a6b66dcd8a 100644 > --- a/bfd/elfnn-riscv.c > +++ b/bfd/elfnn-riscv.c > @@ -4060,6 +4060,7 @@ riscv_relax_delete_bytes (bfd *abfd, > unsigned int sec_shndx =3D _bfd_elf_section_from_bfd_section (abfd, se= c); > struct bfd_elf_section_data *data =3D elf_section_data (sec); > bfd_byte *contents =3D data->this_hdr.contents; > + asymbol **outsyms =3D bfd_get_outsymbols (abfd); > > /* Actually delete the bytes. */ > sec->size -=3D count; > @@ -4158,6 +4159,28 @@ riscv_relax_delete_bytes (bfd *abfd, > } > } > > + /* As linker messages are getting symbols through outsymbols field of = abfd, > + it must be adjusted too. */ > + if (outsyms =3D=3D NULL) > + { > + if (!bfd_generic_link_read_symbols (abfd)) > + link_info->callbacks->einfo (_("%F%P: %pB: could not read symbols= : %E\n"), abfd); > + outsyms =3D bfd_get_outsymbols (abfd); > + } > + > + for (i =3D 0; i < bfd_get_symcount (abfd); i++) > + { > + asymbol *sym =3D outsyms[i]; > + > + if (sym->section !=3D sec) > + continue; > + > + /* If the symbol is in the range of memory we just moved, we > + have to adjust its value. */ > + if (sym->value > addr && sym->value <=3D toaddr) > + sym->value -=3D count; > + } > + > return true; > } > > diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld= -riscv-elf/ld-riscv-elf.exp > index df89e0ee68b..86f1d05bc08 100644 > --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > @@ -176,6 +176,7 @@ if [istarget "riscv*-*-*"] { > [list "Weak reference 64" "-T weakref.ld -m[riscv_choose_lp64_emu= l]" "" \ > "-march=3Drv64i -mabi=3Dlp64" {weakref64.s} \ > {{objdump -d weakref64.d}} "weakref64"]] > + run_dump_test "undefined-align" > > # The following tests require shared library support. > if ![check_shared_lib_support] { > diff --git a/ld/testsuite/ld-riscv-elf/undefined-align.d b/ld/testsuite/l= d-riscv-elf/undefined-align.d > new file mode 100644 > index 00000000000..c8cbb84ac7c > --- /dev/null > +++ b/ld/testsuite/ld-riscv-elf/undefined-align.d > @@ -0,0 +1,5 @@ > +#name: undefined with alignment > +#source: undefined-align.s > +#as: > +#ld: --relax > +#error: \A[^\n]*\.o: in function `_start':\n\(\.text\+0x0\): undefined r= eference to `foo'\Z > diff --git a/ld/testsuite/ld-riscv-elf/undefined-align.s b/ld/testsuite/l= d-riscv-elf/undefined-align.s > new file mode 100644 > index 00000000000..577557c663a > --- /dev/null > +++ b/ld/testsuite/ld-riscv-elf/undefined-align.s > @@ -0,0 +1,10 @@ > +# Make sure that the linker messages take into account the modification > +# of a symbol's value made during the section relaxation. > +# Here, "_start" will have an offset made by ".align 4" which will be > +# removed during the relaxation of R_RISCV_ALIGN. > + .text > + .align 4 > + .globl _start > + .type _start, @function > +_start: > + call foo > -- > 2.25.1 >