From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14895 invoked by alias); 27 Nov 2009 04:58:43 -0000 Received: (qmail 14884 invoked by uid 22791); 27 Nov 2009 04:58:42 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM X-Spam-Check-By: sourceware.org Received: from nwd2mail11.analog.com (HELO nwd2mail11.analog.com) (137.71.25.57) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Nov 2009 04:58:34 +0000 Received: from nwd2hubcas2.ad.analog.com ([10.64.73.30]) by nwd2mail11.analog.com with ESMTP; 26 Nov 2009 23:58:32 -0500 Received: from nwd2exm5.ad.analog.com (10.64.51.20) by NWD2HUBCAS2.ad.analog.com (10.64.73.30) with Microsoft SMTP Server id 8.1.358.0; Thu, 26 Nov 2009 23:58:32 -0500 Received: from chinexm1.ad.analog.com ([10.99.27.42]) by nwd2exm5.ad.analog.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 26 Nov 2009 23:58:32 -0500 Received: from [10.99.29.107] ([10.99.29.107]) by chinexm1.ad.analog.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 27 Nov 2009 12:58:25 +0800 Message-ID: <4B0F5C70.7010102@analog.com> Date: Fri, 27 Nov 2009 04:58:00 -0000 From: Jie Zhang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091125 Shredder/3.0 MIME-Version: 1.0 To: yunfeng zhang CC: Richard Henderson , gcc@gcc.gnu.org, Andrew Haley Subject: Re: No .got section in ELF References: <4df04b840911231758md5a545el2d417b663af1647f@mail.gmail.com> <4df04b840911251824j71fa1d33i2cecc9481617dda5@mail.gmail.com> <4B0DF1EC.30001@redhat.com> <4df04b840911252204g33297e18m8e189c62a0662378@mail.gmail.com> In-Reply-To: <4df04b840911252204g33297e18m8e189c62a0662378@mail.gmail.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-11/txt/msg00764.txt.bz2 On 11/26/2009 02:04 PM, yunfeng zhang wrote: > The result is the same > > #include > > extern int g __attribute__((visibility("hidden"))); > int g; > > int foo(int a, int b) > { > g = a + b; > printf("%x, %x",&g, foo); > return g; > } > > load and call `foo' in the library, an outputting (with vdso) is > cc15bc, cc03fc > and open f.map > 0x15bc, 0x3fc > > It shows Linux simply maps the library to memory *using* library segment layout. > > Using e.cc to call it > > #include > #include > #include > #include > #include > > int main(void) > { > void* handle = dlopen("./f.so", RTLD_NOW); > typedef int (*gso)(int, int); > gso f; > *(void**) (&f) = dlsym(handle, "foo"); > f(1, 2); > return 0; > } > You got the bad test case. Please try the following: $ cat f.c #include int g; int foo(int a, int b) { g = a + b; printf("&g = 0x%x, foo = 0x%x\n", &g, foo); return g; } $ cat e.c int g; extern int foo(int a, int b); int main(void) { foo(1, 2); return 0; } $ gcc -shared -fPIC -Wl,-soname,./libf.so,-Map,f.map -o libf.so f.c $ gcc -o e e.c -ldl -L. -lf $ ./e &g = 0x600a30, foo = 0x294a2614 Then comment out the "int g;" in e.c. and do the same steps as above: $ ./e &g = 0x58294948, foo = 0x58094614 You can see that "C-A" is *not* a constant. Your premise is wrong. Jie