linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Matthew Wilcox <matthew@wil.cx>,
	Andrew Morton <akpm@linux-foundation.org>,
	Adrian Bunk <bunk@kernel.org>,
	Andrea Righi <righi.andrea@gmail.com>,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: __weak vs ifdef
Date: Wed, 17 Feb 2010 18:22:29 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1002171819020.4141@localhost.localdomain> (raw)
In-Reply-To: <fa686aa41002171807s71ac7176l769d78e2bb5d9a1@mail.gmail.com>



On Wed, 17 Feb 2010, Grant Likely wrote:
> 
> Question.  If I use this pattern, and use the __weak attribute on core
> code functions wrapped with a #ifndef, then how does it mesh with
> EXPORT_SYMBOL*() statements?

You can't. Or at least not the traditional way, which is to put the 
EXPORT_SYMBOL next to the definition of what gets exported.

If you use __weak, you need to make sure that all users of said weak 
symbol are in another file. There are some compiler and/or binutils bugs 
with using weak symbols in the same translation unit, so the rule is that 
a weak definition hes to be somewhere else from the use - including 
EXPORT_SYMBOL.

> I also assume that at the core code site, the EXPORT_SYMBOL() must
> appear inside the #ifndef block so that a #define override doesn't
> break things.  Correct?

See above. You can't put it inside the _same_ #ifndef block. You'd have to 
put it in a different file, but yes, inside an ifndef. At which point the 
linker will just pick the right definition.

However, in general, this probably gets ugly enough that the whole __weak 
thing is not great for exported stuff. It's likely mostly useful for some 
"generic" arch functionality that is always compiled in.

		Linus

  reply	other threads:[~2010-02-18  2:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-25  8:39 PAGE_ALIGN() compile breakage Adrian Bunk
2008-07-25  8:55 ` Andrew Morton
2008-07-25  9:14   ` Adrian Bunk
2008-07-25  9:25     ` Andrew Morton
2008-07-25 18:34       ` Andrea Righi
2008-07-25  9:27     ` Adrian Bunk
2008-07-25  9:34       ` Andrew Morton
2008-07-25 12:24         ` __weak vs ifdef Matthew Wilcox
2008-07-25 12:41           ` Andrew Morton
2008-07-26 19:38           ` Linus Torvalds
2010-02-18  2:07             ` Grant Likely
2010-02-18  2:22               ` Linus Torvalds [this message]
2008-07-26 21:22         ` [-mm patch] mm/util.c must #include <linux/sched.h> Adrian Bunk

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=alpine.LFD.2.00.1002171819020.4141@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@kernel.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=righi.andrea@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 NNTP newsgroup(s).