From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id D5B313858D35 for ; Wed, 29 Dec 2021 16:19:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D5B313858D35 Received: by mail-pl1-x62e.google.com with SMTP id x15so16196257plg.1 for ; Wed, 29 Dec 2021 08:19:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xy8ZwOlSVzaGliwYSFIg5ShgDDmyF8fCtrdtmeF/jsI=; b=gZPgrBin20IhkDIeXZkdfoyUnUhWRE97YF50pdipWDLBo1ds58R2PoahPFprxMdYIC bLXROkGWpaQ61mV/1rN2HgXtPgOIa4qoAo4Sny6/zuZZsbGpC6vlJ/Rx9G5huSAMkO3b ggEmpErbfBRVew10EXhn5688JUONYBoLbkfXgkXLc4/+lupco6jO6384D/PaNBJl9zvn ED5VRGIg+KvS5eygUuBYbZjK3LkqQHucsoG99YbiSJ2QOxOmZpH3mUwAMDfy1IWCvUg+ ofG99Idw0Uc/R2zvM7RsnZPENFW6qnciEyr5dM0lpiEPEQPiMZ2q7IcfUgPLBqW7ep28 4tBw== X-Gm-Message-State: AOAM533uHQGFXaiLeSBszHMe5c5sYxfMoE/UEvlSmpgFaQJtSCGTPgrm 2UniRgLUcdXWlLG44mxSfshmr2WlTmA2Mcs53k4= X-Google-Smtp-Source: ABdhPJyFyq6BZVSkoeqcVrR4gg3cPo0vrLtz72lMHHTLXAoVO57FtupwWu/DIuHhwk3eH8qAatiBgLrs2hRfhYTrtPU= X-Received: by 2002:a17:903:191:b0:148:a2e8:2c17 with SMTP id z17-20020a170903019100b00148a2e82c17mr26480210plg.102.1640794743999; Wed, 29 Dec 2021 08:19:03 -0800 (PST) MIME-Version: 1.0 References: <20211228024833.144209-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Wed, 29 Dec 2021 08:18:27 -0800 Message-ID: Subject: Re: [PATCH] ld: Check ELF relocs before allocation To: Alan Modra Cc: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3022.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 29 Dec 2021 16:19:06 -0000 On Tue, Dec 28, 2021 at 11:46 PM Alan Modra wrote: > > On Mon, Dec 27, 2021 at 06:48:33PM -0800, H.J. Lu via Binutils wrote: > > To prepare for DT_RELR implemenation, delay checking ELF relocations > > before allocation so that all input sections have been mapped to output > > sections when relocations are checked. This is only enabled for x86 > > targets. > > Please expand on why this is necessary. "Prepare for DT_RELR > implementation" doesn't tell me much. DT_RELR encodes consecutive R_*_RELATIVE relocations in GOT (the global offset table) in a compact format: https://groups.google.com/g/generic-abi/c/bX460iggiKg On some targets, R_*_RELATIVE relocations are counted and the GOT offsets are allocated when setting the dynamic section sizes after seeing all relocations. R_*_RELATIVE relocations are generated while relocating sections after section layout has been finalized. To prepare for DT_RELR implementation on these targets, we need to delay checking ELF relocations before allocation so that when relocations are checked, all input sections have been mapped to output sections, dynamic symbols are known and R_*_RELATIVE relocations can be counted. DT_RELR encoding may be generated in the relax pass when R_*_RELATIVE relocations and their GOT offsets are known. A later fix up is needed if the final GOT vma is different from when DT_RELR encoding was generated. > Also, it seems to me that you could have made the functional changes > in this patch by implementing an x86 before_allocation routine rather > than introducing a new BFD_JUMP_TABLE_LINK entry. Doing it that way > would result in a much smaller patch with few if any changes to > generic ELF linker code. A new linker function, bfd_link_make_reloc_sections, is added to create dynamic relocation sections after all input files have been opened if relocation check is delayed. Otherwise, the dynamic relocation sections are missing when input sections are being mapped to output sections. It is much cleaner than checking relocations in a before_allocation routine. -- H.J.