All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jed Brown <jed@59a2.org>
To: Ravi Shekhar Jethani <rsjethani@gmail.com>
Cc: Stefan Beller <stefanbeller@googlemail.com>, git@vger.kernel.org
Subject: Re: Rationale behind 'extern' on protypes in .h files
Date: Mon, 23 Dec 2013 09:59:25 -0700	[thread overview]
Message-ID: <87fvpjqz9u.fsf@jedbrown.org> (raw)
In-Reply-To: <CAKTJ_1z-pMePmh4phM2TXSMx0kOjGJ0afQ_JRESggi=k6+y-jA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2202 bytes --]

Ravi Shekhar Jethani <rsjethani@gmail.com> writes:
> To check this I installed the libgit2-dev package which installed:
> /usr/include/git2/*.h , /usr/lib/libgit2.so
> Now, I exported all symbols using:
> $ readelf -s /usr/lib/libgit2.so
> and tried to match these with 'externed' prototypes in the Git source
> directory..no matches.
> I am confused!!!.

libgit2 is an entirely different package from Git.  If you look at the
libgit2 sources (https://github.com/libgit2/libgit2), look in
include/git2/common.h:

/** Declare a public function exported for application use. */
#if __GNUC__ >= 4
# define GIT_EXTERN(type) extern \
                         __attribute__((visibility("default"))) \
                         type
#elif defined(_MSC_VER)
# define GIT_EXTERN(type) __declspec(dllexport) type
#else
# define GIT_EXTERN(type) extern type
#endif


I have always used __attribute__((visibility("default"))), but the gcc
man page says

    extern declarations are not affected by -fvisibility, so a lot of
    code can be recompiled with -fvisibility=hidden with no
    modifications.  However, this means that calls to "extern" functions
    with no explicit visibility use the PLT, so it is more effective to
    use "__attribute ((visibility))" and/or "#pragma GCC visibility" to
    tell the compiler which "extern" declarations should be treated as
    hidden.

However, I don't understand what the first statement means
(documentation bug?) since -fvisibility=hidden causes functions declared
with 'extern' to be hidden.

symbols.c:
EXTERN int foo(void);
int foo(void) {return 1;}

$ gcc -fvisibility=hidden -DEXTERN=extern -shared -o libsymbols.so symbols.c
$ nm -D libsymbols.so | grep foo
$

meanwhile,

$ gcc -fvisibility=hidden -DEXTERN='__attribute((visibility("default")))' -shared -o libsymbols.so symbols.c
$ nm -D libsymbols.so | grep foo
000000000000055c T foo

> Also I checked this:
> $ ldd git
> There is no 'gitish' .so in the output; it seems everything is packed
> inside one executable.
> So your second point 'skipping the PLT...' also doesn't seem to apply here.

My comment applied to shared libraries in general, not specifically to
Git (which isn't a shared library).

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

      reply	other threads:[~2013-12-23 16:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-22 15:51 Rationale behind 'extern' on protypes in .h files Ravi Shekhar Jethani
2013-12-22 17:11 ` Stefan Beller
2013-12-22 18:26   ` Jed Brown
2013-12-23 15:24     ` Ravi Shekhar Jethani
2013-12-23 16:59       ` Jed Brown [this message]

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=87fvpjqz9u.fsf@jedbrown.org \
    --to=jed@59a2.org \
    --cc=git@vger.kernel.org \
    --cc=rsjethani@gmail.com \
    --cc=stefanbeller@googlemail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.