From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1D5D83858C98 for ; Fri, 5 Apr 2024 15:38:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D5D83858C98 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D5D83858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712331506; cv=none; b=grMRZOyhxLB0i9sCAb1v1aATTfh3wmbvTpTXQJikWe/+9U7O4mxbLCG0RgL6m90Xi158A/OsHzrnwm1uoLnjJvznAtqP7Eckhyy87Y8RNYMow6MP4SHyh4Eupt+7m1AiRfq/zbD1RYMuTTNzM0wYnu5IbHBLs79BHaPXxRdbTq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712331506; c=relaxed/simple; bh=lekbp6JLGJ7F9qSv+5y9UQKQQ8F4p+3aC5ozHTXnaSw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=A5QnGPtwE3HU0EeqGoUZ3ebYwAPVqxQnjzUKdmdsS4djOHyuBFXeXF6i0Hf4RD3+xUejIHVpRckrnEPYp2YyAxRybX9OnQkj/l8aAT9toctRGK+PtjYGYXXpymd/T//wqjW25E5P/lZOchleZeD4aUaK6ivxfvwnap/mJ8U5iP0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ecec796323so1899039b3a.3 for ; Fri, 05 Apr 2024 08:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1712331503; x=1712936303; darn=sourceware.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=n2vV3HTcgt3dO36yLogtS27ztme+o6FzEzzD5cKzFBs=; b=S2Led0xg15yRcSPg9I6wqGKEGK4hsm1tGunlEYfGpEwP7qaIta/V5T83klqfMwVppx k1SJeywct0soN6o2yJPelYn0GjKFHuDYTwaA4VGTGcz8rUBiD4XskJUpGnm1Xf0jfid+ 4KJ7BeBokHC+IdW2imW3nkkvs3aiJ/+98+R/o8je1GuD27HPwZBxxy2m/pjjc2l3/Mqr HxOm9iUZeHvatU+ynKSVNUHE9qvvghDg6UPxzTE1IX6fBwTJZPw+m6TVbzc6ZiN7pHbe 4kP+9DDWa/kfy7UXXP6vLnJoTEpGlxmXuVhbRcDs64m8mXls2XTYtWHq6CMPcDYDSqeL 8mFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712331503; x=1712936303; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n2vV3HTcgt3dO36yLogtS27ztme+o6FzEzzD5cKzFBs=; b=dQDeEb/DN+CxvMcyNvYAVrZOh310Z7pCPnvX609OxW5K1vZ+lNXtVA4JG8/DbUoF58 THpAiB1KCQpiKsXpJSOwVedpUg90qj31QIDvnCffcJMxuU2oKolcaeCJLH0bW7e+lYdO QE6i+AZIizZbviab2zMqxCIAM5Z4Uxo2hbQbM5x6unRu0wmMnXWgQstaV9Ay7iLtTTWL GALJhz+8O0e8aKy6Y0rSKHgYGecBj+Cmv/HonFmuqTVtl5kUIDitDVODVDkA18aa8ECt BrHirbdLydeH8HKE0+HHJ9cP4vmA0ylgpXixk+l2Ud2cxRoG/pI281BnXjtXTQxxDag+ m1Sg== X-Gm-Message-State: AOJu0YxgiTZNhniTinUtuNgpfX0vsEF1JC4Z4QwfAQ8lwyebR6HfO45j U4BkfrQYSUZMGAcc3ZQoToIKIAr/JnqTn19UZ1T8jLYC76E707UoNZLWYm9cavv0aP1pDmJzbvE qPg== X-Google-Smtp-Source: AGHT+IFyglpoOM/cbPzhmUFc2F2D/MutF1JBLYEPFy4qIZWNxzKqS2UrjABsHfKPOWzEZLeFIIHh1w== X-Received: by 2002:a05:6a21:3388:b0:1a7:23ae:92c3 with SMTP id yy8-20020a056a21338800b001a723ae92c3mr2350924pzb.12.1712331502683; Fri, 05 Apr 2024 08:38:22 -0700 (PDT) Received: from free.home ([2804:7f1:218b:1ca:78e3:32cc:f126:89aa]) by smtp.gmail.com with ESMTPSA id fb39-20020a056a002da700b006ecfc3a8d6csm1632594pfb.124.2024.04.05.08.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 08:38:21 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 435Fc6xw1939295 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 5 Apr 2024 12:38:07 -0300 From: Alexandre Oliva To: binutils@sourceware.org Subject: avoiding undesirable undef[weak] syms after relocatable linking Organization: Free thinker, does not speak for AdaCore Date: Fri, 05 Apr 2024 12:38:06 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,WEIRD_QUOTING 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: The following, say t.s, is dystilled from libstdc++-v3's floating_to_chars.o: .section .text.foobar,"axG",@progbits,foo,comdat .weak foo .type foo,@function foo: # .dc.a undef .size foo, . - foo .weak bar .set bar, foo .text .global baz .type baz,@function baz: .dc.a foo .size baz, . - baz The weak definitions were originally implicit instantiations of to_chars_i, and the aliases were originally meant for abi compatibility because of changes in int128_t mangling. The following, say m.s, is dystilled from a libstdc++-v3/testsuite/std/time/clock/system/io.cc: .section .text.foobar,"axG",@progbits,foo,comdat .weak foo .type foo,@function foo: .size foo, . - foo .text .global _start .set _start,foo .dc.a baz And here's how to trigger the problem: as t.s -o t.o && ar cr t.a t.o && ranlib t.a && as m.s -o m.o && ld m.o -o m -r && nm m | grep bar w bar This is probably expected behavior: the weakly-defined symbol in the archive lives in a discarded section, so it decays to weak-undefined, and it most likely goes unnoticed on systems that support undefweak. If this were a final link, the bar symbol would be gone. So would the undef symbol, if the reference to it in t.s were uncommented. But because this is a relocatable link, both undefined symbols would remain. Both of them are a problem for e.g. vxworks kernel modules, that never undergo final linking, and whose loader rejects undefined symbols, even weak ones, if they're not defined elsewhere. I hoped --strip-discarded would get rid of undef, if not bar, but no such luck. Could we arrange for it to do so, even in relocatable linking? Or should we aim for another option to make -r (and -shared?) linking behave more like final linking when it comes to discarding unreferenced undefined symbols? Thoughts? Recommendations? Thanks in advance, -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive