public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jie Zhang <jie.zhang@analog.com>
To: yunfeng zhang <zyf.zeroos@gmail.com>
Cc: Richard Henderson <rth@redhat.com>,
	gcc@gcc.gnu.org,   Andrew Haley <aph@redhat.com>
Subject: Re: No .got section in ELF
Date: Fri, 27 Nov 2009 04:58:00 -0000	[thread overview]
Message-ID: <4B0F5C70.7010102@analog.com> (raw)
In-Reply-To: <4df04b840911252204g33297e18m8e189c62a0662378@mail.gmail.com>

On 11/26/2009 02:04 PM, yunfeng zhang wrote:
> The result is the same
>
> #include<stdio.h>
>
> 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<exception>
> #include<typeinfo>
> #include<cstddef>
> #include<dlfcn.h>
> #include<stdio.h>
>
> 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 <stdio.h>
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

  parent reply	other threads:[~2009-11-27  4:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-24  1:58 yunfeng zhang
2009-11-24 10:00 ` Andrew Haley
2009-11-24 17:10 ` Richard Henderson
2009-11-26  2:24 ` yunfeng zhang
2009-11-26  3:11   ` Richard Henderson
2009-11-26  6:04     ` yunfeng zhang
2009-11-26  7:55       ` Alexandre Oliva
2009-11-27  2:18         ` yunfeng zhang
2009-11-27  4:12           ` Dave Korn
2009-11-27  4:43             ` yunfeng zhang
2009-11-27  4:46               ` Dave Korn
2009-11-27 13:35           ` Alexandre Oliva
2009-11-30 11:10             ` Yunfeng ZHANG
2009-11-27  4:58       ` Jie Zhang [this message]
2009-11-27  6:42         ` yunfeng zhang
2009-11-27 14:16           ` Ian Lance Taylor
2009-11-27  4:51 Dmitry Gorbachev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B0F5C70.7010102@analog.com \
    --to=jie.zhang@analog.com \
    --cc=aph@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=rth@redhat.com \
    --cc=zyf.zeroos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).