Prev: [tip:x86/irq] init: Move radix_tree_init() early
Next: Direct compact when a high-order allocation fails
From: Grant Likely on 17 Feb 2010 21:10 Reaching back into an old discussion.... On Sat, Jul 26, 2008 at 12:38 PM, Linus Torvalds <torvalds(a)linux-foundation.org> wrote: > > > On Fri, 25 Jul 2008, Matthew Wilcox wrote: > >> On Fri, Jul 25, 2008 at 02:34:55AM -0700, Andrew Morton wrote: >> > We should make arch_pick_mmap_layout __weak and nuke that ifdef. >> >> I strongly disagree. �I find it makes it harder to follow code flow >> when __weak functions are involved. �Ifdefs are ugly, no question, but >> they're easier to grep for > > Hell no, they're not. > > Our use of random HAVE_ARCH_xyz or ARCH_SUPPORTS_xyz etc stuff makes > things _totally_ impossible to grep for. > > In contrast, it we did this code as > > � � � �#ifndef arch_pick_mmap_layout > � � � �void __weak arch_pick_mmap_layout(struct mm_struct *mm) > � � � �{ > � � � � � � � �mm->mmap_base = TASK_UNMAPPED_BASE; > � � � � � � � �mm->get_unmapped_area = arch_get_unmapped_area; > � � � � � � � �mm->unmap_area = arch_unmap_area; > � � � �} > � � � �#endif > > then trying to grep for arch_pick_mmap_layout() would show EVERY SINGLE > RELEVANT CASE! And it would show the "__weak" there too, so that once > people get used to this convention, they'd have a really easy time > figuring out the rules from just the output of the 'grep'. [...] 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? Do both the core code, and the arch override need to do EXPORT_SYMBOL(), or should EXPORT_SYMBOL() only appear at the core code site? 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? Cheers, g. -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Linus Torvalds on 17 Feb 2010 21:30
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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ |