From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 73EAE3858D1E for ; Wed, 29 Mar 2023 16:00:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73EAE3858D1E 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 8B46B219C0; Wed, 29 Mar 2023 16:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680105613; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0gHnX4ijgFQi82og/8MSize5yu14KM1eIJSxqP8Ri8M=; b=fL1JthItV8ZZXI59Bh17thal+UpJLgQtVCw+thWi3a6uXBZcM/WAHBumPkzisq+2Vy8PDX zSiYbAtYDB8lIcgLkCRDvnNIvc66kkXgVbnVGL+YGgWT/UpTZXMezCTmF1jiNH3PvhXzfB qbhd9SYZ43sKgD1M8hidFZbhnVlFmOw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680105613; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0gHnX4ijgFQi82og/8MSize5yu14KM1eIJSxqP8Ri8M=; b=MDHM4d7Eg2nppW50Uzpa0yTE/KHgt3s8z4Vd30yUp/t/ak5SCeLjzRpHChpDMiJDq1XkuK XbmmUkhdk58WQkAg== 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 53F622C195; Wed, 29 Mar 2023 16:00:13 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 2FA036412; Wed, 29 Mar 2023 16:00:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 2E443623C; Wed, 29 Mar 2023 16:00:13 +0000 (UTC) Date: Wed, 29 Mar 2023 16:00:12 +0000 (UTC) From: Michael Matz To: Nick Clifton cc: binutils@sourceware.org, mjw@fedoraproject.org, amulhern@redhat.com Subject: Re: RFC: Can static executables contain relocations against symbols ? In-Reply-To: <87v8ijmxjh.fsf@redhat.com> Message-ID: References: <87v8ijmxjh.fsf@redhat.com> 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=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: Hello, On Wed, 29 Mar 2023, Nick Clifton via Binutils wrote: > Can static executables contain relocations against symbols ? Generally I agree with you that they should not. Only symbol-less relocations make sense (not all of them will be absolute, though. In PIEs they will be base-relative, still symbolless of course). But for the sake of discussion let's assume we somehow want to allow symbol-based relocs nevertheless. Then: In final-linked ELF files symbol headers always have to be optional. The place of relocations, if necessary, (and symbols) needs to be communicated in a different way anyway (on dynamic ELF files via the program headers and dynamic entries, on static files via some other side channel, like hardcoding the offset/addresses of the interesting pieces). But: there is another observation that makes the Rust output invalid. An allocated (SHF_ALLOC) section (here .got.rela) _must_ only refer to allocated sections via its sh_link field. The .symtab section in the example at hand was not SHF_ALLOC. So that's another bug. Leaving a sh_link field of an SHT_RELA section to be zero seems a bit dubious. Normally client code would be able to rely on sh_link containing an existing section index. OTOH SHN_UNDEF (i.e. zero) _is_ somewhat of a section index, so leaving it as zero might just be fine. So, even if the above problems would be fixed I think your patch still makes sense. Perhaps add another check to only leave it zero if elf_onesymtab is not allocated itself. Ciao, Michael.