From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91060 invoked by alias); 22 Feb 2016 17:50:11 -0000 Mailing-List: contact gnu-gabi-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: gnu-gabi-owner@sourceware.org Received: (qmail 91044 invoked by uid 89); 22 Feb 2016 17:50:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2439, Relocation X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mail-qg0-f42.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0wm5qhtz3y1zGMSVGCQPZnue3yMHav5gTzlosfIJUFk=; b=AE+pMc0syhNC6SLn1UTXI5GtCt6SQ74NYgVQ+PLEsw3NgCwztvTpWHWg5Csfw3KY3c fvT0HELIRyeYmsmpa1BaDU4HU4VDRdMLUQ5cMZ4klfd+bQIHRiMdGXez60T/tlAqZKM1 L4AqFUmjCTJGb4+IOmWW5Pdhm3JYAyYnCFYbQK+5EmSNuUGglu+0UtHmOcfHS1MzBUMZ 7gBINheahVq4GH5rPr7+foe1dUemGRPvkT3FIeqAYtA+8F9d3LOU3V7bN5Yf9FpxTOcI Eam04xsnSk7YRbWxpIWsVN7EWRluLbpWuZ1pCcRCsZAfQIxUWQriqD/D2qjToDJY+4Is zlkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=0wm5qhtz3y1zGMSVGCQPZnue3yMHav5gTzlosfIJUFk=; b=XQuD4hYJk8q/6UQGsd/vVZrZsCSYhJeGDfV0BYDEyMiD2My/5fLki+Ec3A8ltVEiQJ EsTbQwWMW0NboNS/m0c66N3MzlXnlWFEc6KOMJniKTgf/yfkutFGBmyjKd6RJsk8z1Yl 4QfK+eu+aJOZzUcR+Mq8h4JiKvj9xgA0D2L19qypYMRkEevTqnNJjSy7tbjqSoNoMvV5 P5E2kL1Ecq/OaG5tfOqnoZPizSCTpxGu1yu6NE4HYD1e9UsJbjxvIJyUXJ74dCfiehtO aThUqZ4lydX/yCePIZTqP3UwyP36L0XVhBEiCY0GjRaaBp+I/cGdfHhSKM6UB8eOnrNC GcVA== X-Gm-Message-State: AG10YORmamT595M8mPF6w6ILfE/mK2Su9kZYRuc7hERwYjREv9Wy/WhVVY4u/Aox6hKdn0Hhs4HZ8lhJRfFW8Q== MIME-Version: 1.0 X-Received: by 10.140.23.139 with SMTP id 11mr206165qgp.62.1456163407787; Mon, 22 Feb 2016 09:50:07 -0800 (PST) In-Reply-To: References: Date: Fri, 01 Jan 2016 00:00:00 -0000 Message-ID: Subject: Re: Specify how undefined weak symbol should be resolved in executable From: "H.J. Lu" To: gnu-gabi@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2016-q1/txt/msg00006.txt.bz2 On Mon, Feb 22, 2016 at 9:45 AM, H.J. Lu wrote: > On Mon, Feb 22, 2016 at 8:25 AM, H.J. Lu wrote: >> Currently when building executable, undefined weak symbol is resolved >> differently, depending on if the relocatable input is compiled with PIC or >> not: >> >> hjl@gnu-tools-1 weak-1]$ cat x.c >> extern void __attribute__ ((weak)) fun (void); >> int main (void) >> { >> if (&fun != 0) >> fun (); >> return 0; >> } >> [hjl@gnu-tools-1 weak-1]$ make >> gcc -B./ -O2 -o x x.c >> gcc -B./ -O2 -o y x.c -fPIC >> readelf -r x >> >> Relocation section '.rela.dyn' at offset 0x328 contains 1 entries: >> Offset Info Type Sym. Value Sym. Name + Addend >> 000000600870 000200000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 >> >> Relocation section '.rela.plt' at offset 0x340 contains 1 entries: >> Offset Info Type Sym. Value Sym. Name + Addend >> 000000600890 000100000007 R_X86_64_JUMP_SLO 0000000000000000 >> __libc_start_main@GLIBC_2.2.5 + 0 >> >> There is no dynamic relocation against fun, whose value is >> resolved to zero at link-time. >> >> readelf -r y >> >> Relocation section '.rela.dyn' at offset 0x348 contains 2 entries: >> Offset Info Type Sym. Value Sym. Name + Addend >> 0000006008a0 000100000006 R_X86_64_GLOB_DAT 0000000000000000 fun + 0 >> 0000006008a8 000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 >> >> Relocation section '.rela.plt' at offset 0x378 contains 1 entries: >> Offset Info Type Sym. Value Sym. Name + Addend >> 0000006008c8 000200000007 R_X86_64_JUMP_SLO 0000000000000000 >> __libc_start_main@GLIBC_2.2.5 + 0 >> [hjl@gnu-tools-1 weak-1]$ >> >> There is dynamic relocation against fun, whose value is resolved >> at runt-time. We should make it consistent, regardless if input >> relocatable file is compiled with PIC or not. >> >> I raised the issue at gABI: >> >> https://groups.google.com/d/msg/generic-abi/Ckq19PfLxyk/eCbXPofkAQAJ >> >> But if gABI change is incompatible with other OSes, we need to >> specify it in GNU ABI. > > We should extend GNU ABI to: > > When creating executable, if dynamic relocation is available at > run-time, the link > editor should generate dynamic relocations against unresolved weak symbols so > that their values will be resolved at run-time. > I opened: https://sourceware.org/bugzilla/show_bug.cgi?id=19704 -- H.J.