From: Andrew Morton <akpm@zip.com.au>
To: Momchil Velikov <velco@fadata.bg>
Cc: Oliver Xymoron <oxymoron@waste.org>,
vda <vda@port.imtp.ilyichevsk.odessa.ua>,
linux-kernel@vger.kernel.org, "H . J . Lu" <hjl@lucon.org>
Subject: Re: Extern variables in *.c files
Date: Wed, 02 Jan 2002 23:19:29 -0800 [thread overview]
Message-ID: <3C340601.E9A3507F@zip.com.au> (raw)
In-Reply-To: <02010216180403.01928@manta> <Pine.LNX.4.43.0201021322120.30079-100000@waste.org> <3C337EF1.4C7C72AB@zip.com.au>, <3C337EF1.4C7C72AB@zip.com.au> <87ell8wgo9.fsf@fadata.bg>
Momchil Velikov wrote:
>
> >>>>> "Andrew" == Andrew Morton <akpm@zip.com.au> writes:
>
> Andrew> Oliver Xymoron wrote:
> >>
> >> On Wed, 2 Jan 2002, vda wrote:
> >>
> >> > I grepped kernel *.c (not *.h!) files for extern variable definitions.
> >> > Much to my surprize, I found ~1500 such defs.
> >> >
> >> > Isn't that bad C code style? What will happen if/when type of variable gets
> >> > changed? (int->long).
> >>
> >> Yes; Int->long won't change anything on 32-bit machines and will break
> >> silently on 64-bit ones. The trick is finding appropriate places to put
> >> such definitions so that all the things that need them can include them
> >> without circular dependencies.
> >>
>
> Andrew> Isn't there some way to get the linker to detect the differing
> Andrew> sizes?
> `--warn-common'
> Warn when a common symbol is combined with another common symbol
> or with a symbol definition. Unix linkers allow this somewhat
> sloppy practice, but linkers on some other operating systems do
> not. This option allows you to find potential problems from
> combining global symbols. Unfortunately, some C libraries use
> this practice, so you may get some warnings about symbols in the
> libraries as well as in your programs.
>
Alas, it doesn't quite work as we'd like:
akpm-1:/home/akpm> cat a.c
int a;
main()
{}
akpm-1:/home/akpm> cat b.c
extern char a;
int b()
{return a;}
akpm-1:/home/akpm> gcc -fno-common -Wl,--warn-common a.c b.c
akpm-1:/home/akpm>
No warnings emitted. If b.c doesn't use `extern' it will fail
to link because of -fno-common.
What we'd *like* to happen is for the linker to determine that
the `extern char' and the `int' declarations are a mismatch.
Maybe the object file doesn't have the size info for `extern'
variables. The compiler emits it though.
We can actually get what we want by disabling `-fno-common' and enabling
`--warn-common', but that's rather awkward.
Perhaps HJ can suggest a solution?
-
next prev parent reply other threads:[~2002-01-03 7:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-02 18:18 Extern variables in *.c files vda
2002-01-02 19:24 ` Oliver Xymoron
2002-01-02 21:43 ` Andrew Morton
2002-01-02 22:07 ` Momchil Velikov
2002-01-03 7:19 ` Andrew Morton [this message]
2002-01-03 7:42 ` H . J . Lu
2002-01-03 7:56 ` Andrew Morton
2002-01-03 8:24 ` Keith Owens
2002-01-03 9:57 ` Russell King
2002-01-04 0:28 ` Extern variables in *.c files (maintainers pls read this) vda
2002-01-03 23:14 ` Olaf Dietsche
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=3C340601.E9A3507F@zip.com.au \
--to=akpm@zip.com.au \
--cc=hjl@lucon.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oxymoron@waste.org \
--cc=vda@port.imtp.ilyichevsk.odessa.ua \
--cc=velco@fadata.bg \
/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.