From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.4 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 15E731F5AE for ; Mon, 3 May 2021 01:45:08 +0000 (UTC) Received: from localhost ([::1]:48262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldNdy-0003ED-SW for normalperson@yhbt.net; Sun, 02 May 2021 21:45:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldNdv-0003Dn-NC for bug-gnulib@gnu.org; Sun, 02 May 2021 21:45:03 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:35774) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldNdu-0004Vz-0R for bug-gnulib@gnu.org; Sun, 02 May 2021 21:45:03 -0400 Received: by mail-pg1-x535.google.com with SMTP id q10so2622683pgj.2 for ; Sun, 02 May 2021 18:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ML9XLCyjbckcSiZbJM80DFQO0Of7S3z58gr+cmuUCqc=; b=WkQp5k2GRctuHzOqd3AMSxAOr34XgkeIA9QvLEZ3jNSqju+8Rbz/HftgXPra6A/17e 0OSAS53LaTKSjr0d+V0EEyJNvKvylSpFeCBq6rHlomdnMaxwm3cgKgflsa1dId5C3td+ GTNxudbjUe4NgKwi5R5TcYhgHoVDUt+6KDMeJTyi8xAiobr33qIooaLPEJOazBZcW6NR +60Yw5fjenUUknItpFpMaeXevgPKLHXmmtNINzgYFN9Q+r5gK2V5azjZu31Ss6SODSfM fXjnet2z91jSn41ypFDFJvH5tdWEbyDHPlwDK/C7xerVRTkEUP29gZTO8/3cewWO+I0H 1bfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ML9XLCyjbckcSiZbJM80DFQO0Of7S3z58gr+cmuUCqc=; b=lOMACOcwVCIvpuKfqtfTkJi8eosDDw1mhdCY7UG6FFNHgX1sPENH2/SQyScVFMedeu 0gd4TY3fLQCNzsq3PvLae3sKUTUkVd4uA8KVorsIdr+RfxZDtld4FOMN5q4WPAO3jy1l 5fM0crbWonCSIzXSLuLrw7oc1KicYzt0QjmlpPt5/kDn9+s3On8ckvbKFILBz70vV2Kt XRhNlYmP+Gf0hMQcO4/haQZTaHt7KqNdYgoQQWZxhyKd2bFEk0WjHRI1EYPoybtAGnLI y+ysLpKV5cJ36+VmR6l6RPCVdW2Tk0gPYfHILcJmfZr6QI/hNstPsKyz8qDooGax2VRK FvVg== X-Gm-Message-State: AOAM533y5p9jKZxlYfFiSWgtEpBzSOt4T0u8uPW2lHJ/0FvTsFVfi1Yl 2MA9VaRAEd8JnkKiFIv1CsXg8U+y6iWJ0Q== X-Google-Smtp-Source: ABdhPJyOlzBl129hTapFlRvsNw6W0W8pUZ0v4E8GqUqQwg9NfCzQQrFhF5nRIFQv943OapCQ8AlBEw== X-Received: by 2002:a63:5801:: with SMTP id m1mr15831625pgb.424.1620006299449; Sun, 02 May 2021 18:44:59 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id h1sm7445891pfh.72.2021.05.02.18.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 18:44:58 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id A6C0241B0A; Mon, 3 May 2021 11:14:54 +0930 (ACST) Date: Mon, 3 May 2021 11:14:54 +0930 From: Alan Modra To: Florian Weimer Subject: Re: Undefined use of weak symbols in gnulib Message-ID: <20210503014454.GA5774@bubble.grove.modra.org> References: <87o8e0p92r.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o8e0p92r.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=amodra@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libc-alpha@sourceware.org, bug-gnulib@gnu.org, binutils@sourceware.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" On Tue, Apr 27, 2021 at 07:53:16AM +0200, Florian Weimer via Binutils wrote: > So the net effect is this: > > if (pthread_mutexattr_gettype != NULL) > pthread_once (control, callback); > > Dynamic linking with weak symbols is not very well-defined. On x86-64, > the link editor produces the expected dynamic symbol relocation for the > pthread_once call. On other targets (notably POWER), no dynamic > relocation is produced, and the code will crash if > pthread_mutexattr_gettype is ever defined. Yes, this construct is not handled in ppc32 and ppc64 ld. It also doesn't work with some combination of compiler flags on x86. Don't allow yourself to be fooled by only testing with compilers that default to -fpie.. For example, this on x86_64 with gcc-11 (and previous versions). $ cat ~/src/tmp/weakfunc2.c extern void func1 (void) __attribute__((weak)); extern void func2 (void) __attribute__((weak)); int main (void) { if (func1) func2 (); return 0; } $ gcc -O2 -c -fno-pie ~/src/tmp/weakfunc2.c $ gas/as-new -o empty.o /dev/null $ ld/ld-new -shared -o empty.so empty.o $ ld/ld-new -o weakfunc2 weakfunc2.o empty.so ld/ld-new: warning: cannot find entry symbol _start; defaulting to 0000000000401020 $ binutils/nm-new --dynamic weakfunc2 w func2 So func1 is resolved to zero at link time. Well, I guess that isn't unexpected. powerpc-linux and powerpc64-linux (both ABIs) have further problems that I'll fix. In particular the above testcase ought to work even though it looks wrong to test func1 non-NULL and then call func2. Slightly less weird is if (func1) { func1 (); func2 (); } which might be reasonable user code when it is known that func1 and func2 both exist or are both NULL. ppc gets that one wrong too. -- Alan Modra Australia Development Lab, IBM