From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59300 invoked by alias); 22 Feb 2016 17:45:56 -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 58617 invoked by uid 89); 22 Feb 2016 17:45:56 -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.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Relocation, run-time, Addend X-Spam-Status: No, score=-2.3 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-qk0-f181.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=gPAE+u+si273LOB2KnhkbYEIJhU5MNrLctSTsOQ8Z24=; b=CvfCKmYbRXOseEW8xQ3BCJowIl0x1Rr7A9uUvN0VNxt9z1ZxF6cG4NwACTC5cPp4h8 YQ3xmnRzVpMS+omaL36fDrvJ+68kvHZ8/NK+PMfy63W5mgLPfakGWPwBjA8LkkQLGag7 q1+e2N6SYem0fExXjOD1ddA1h0nA2JVJ5ibNwum2px0qOunLbPmmMRbXw6HhAr1h6ZcS oJ5Vol7ng9MHjWpLMNk1v+daqHh8CFwqEle9ci+3kaOGihP7KCW6zcEqe7kOEQtVv0Uv vSaZFJfYqMI0CGe/a1tylXRj7zPoqZMU/AbAophjXWmk6dTmHj8P7OGQQ2mRFFKXSm/+ 12Fg== 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=gPAE+u+si273LOB2KnhkbYEIJhU5MNrLctSTsOQ8Z24=; b=HhXdaOhK+PWaQYYM+SvJsePAX1VoXNTabpWwbOs4wXq2lsmPWOsGJ7d86KOco/o/bg hU7St6XLdE/+of6u2glDkckHLXB+4A5hqbptIUB65KMj3BRrZLTBw7foXI2WtEcVVB65 Cvq/CAppFC6zoLHUVkmBAGin7hGWTJys4df6DsydN1GcNVMu2kTYq8i6pMtEl2fKF53t qjK3rPRlPnORxFkhTwAnPzzKCdhZ1gAI2sVK8EmQLIK1FvZjqKUhaumdscDpSLAy+bAs L5eKPq9OtjsqwEgl4Fi4KuQuISY//eyyVjtXf+tnBvyvxZI0D064hPMgSnXJSVWjJbKy DsBQ== X-Gm-Message-State: AG10YOQuV0y49daatxxKtRzZPJCl8t+Wbft/asQTzbN5ku0iHJsi5iMKAdycnqVX0ksloiGAkwG/Ujs6VYOUpA== MIME-Version: 1.0 X-Received: by 10.55.80.131 with SMTP id e125mr35991649qkb.62.1456163152899; Mon, 22 Feb 2016 09:45:52 -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/msg00005.txt.bz2 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. -- H.J.