public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* __attribute__((unused))
@ 2004-10-14 21:02 Russell King
  2004-10-14 22:04 ` __attribute__((unused)) David Woodhouse
  2004-10-15 12:33 ` __attribute__((unused)) Frank van Maarseveen
  0 siblings, 2 replies; 8+ messages in thread
From: Russell King @ 2004-10-14 21:02 UTC (permalink / raw)
  To: Linux Kernel List

Hi,

I notice that module.h contains stuff like:

#define MODULE_GENERIC_TABLE(gtype,name)                        \
extern const struct gtype##_id __mod_##gtype##_table            \
  __attribute__ ((unused, alias(__stringify(name))))

and even:

#define __MODULE_INFO(tag, name, info)                                    \
static const char __module_cat(name,__LINE__)[]                           \
  __attribute_used__                                                      \
  __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info

My understanding is that we shouldn't be using __attribute__((unused))
in either of these - can someone confirm.

The second one looks fairly dodgy since we're telling a compiler that
it's both used and unused.  That sounds a bit like a HHGTTG puzzle (you
have tea and no tea.)

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-14 21:02 __attribute__((unused)) Russell King
@ 2004-10-14 22:04 ` David Woodhouse
  2004-10-14 22:08   ` __attribute__((unused)) Russell King
  2004-10-15 12:33 ` __attribute__((unused)) Frank van Maarseveen
  1 sibling, 1 reply; 8+ messages in thread
From: David Woodhouse @ 2004-10-14 22:04 UTC (permalink / raw)
  To: Russell King; +Cc: Linux Kernel List

On Thu, 2004-10-14 at 22:02 +0100, Russell King wrote:
> Hi,
> 
> I notice that module.h contains stuff like:
> 
> #define MODULE_GENERIC_TABLE(gtype,name)                        \
> extern const struct gtype##_id __mod_##gtype##_table            \
>   __attribute__ ((unused, alias(__stringify(name))))
> 
> and even:
> 
> #define __MODULE_INFO(tag, name, info)                                    \
> static const char __module_cat(name,__LINE__)[]                           \
>   __attribute_used__                                                      \
>   __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
> 
> My understanding is that we shouldn't be using __attribute__((unused))
> in either of these - can someone confirm.

Since the structure in question isn't explicitly referenced from
elsewhere, the compiler may feel free to omit it. Since we want the
compiler to emit it, not omit it, we use "unused" to say "yes, I know it
looks unused; please emit it anyway". Later compilers use "used" to say
"I use it really; please emit it anyway", meaning much the same thing.

Or something like that.

-- 
dwmw2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-14 22:04 ` __attribute__((unused)) David Woodhouse
@ 2004-10-14 22:08   ` Russell King
  2004-10-14 23:28     ` __attribute__((unused)) Maciej W. Rozycki
  2004-10-15 12:31     ` __attribute__((unused)) Alan Cox
  0 siblings, 2 replies; 8+ messages in thread
From: Russell King @ 2004-10-14 22:08 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Linux Kernel List

On Thu, Oct 14, 2004 at 11:04:56PM +0100, David Woodhouse wrote:
> On Thu, 2004-10-14 at 22:02 +0100, Russell King wrote:
> > Hi,
> > 
> > I notice that module.h contains stuff like:
> > 
> > #define MODULE_GENERIC_TABLE(gtype,name)                        \
> > extern const struct gtype##_id __mod_##gtype##_table            \
> >   __attribute__ ((unused, alias(__stringify(name))))
> > 
> > and even:
> > 
> > #define __MODULE_INFO(tag, name, info)                                    \
> > static const char __module_cat(name,__LINE__)[]                           \
> >   __attribute_used__                                                      \
> >   __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
> > 
> > My understanding is that we shouldn't be using __attribute__((unused))
> > in either of these - can someone confirm.
> 
> Since the structure in question isn't explicitly referenced from
> elsewhere, the compiler may feel free to omit it. Since we want the
> compiler to emit it, not omit it, we use "unused" to say "yes, I know it
> looks unused; please emit it anyway". Later compilers use "used" to say
> "I use it really; please emit it anyway", meaning much the same thing.

It's the "later compilers" which I'm worried about here - I think they
defined "unused" to mean "this really really isn't used and you can
discard it".  Hence my concern with the above.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-14 22:08   ` __attribute__((unused)) Russell King
@ 2004-10-14 23:28     ` Maciej W. Rozycki
  2004-10-15 12:31     ` __attribute__((unused)) Alan Cox
  1 sibling, 0 replies; 8+ messages in thread
From: Maciej W. Rozycki @ 2004-10-14 23:28 UTC (permalink / raw)
  To: Russell King; +Cc: David Woodhouse, Linux Kernel List

On Thu, 14 Oct 2004, Russell King wrote:

> It's the "later compilers" which I'm worried about here - I think they
> defined "unused" to mean "this really really isn't used and you can
> discard it".  Hence my concern with the above.

 Your concern is valid.  Much enough it's been already fixed in 2.4.27, so
I suppose 2.6 deserves the fix, too.

  Maciej

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-14 22:08   ` __attribute__((unused)) Russell King
  2004-10-14 23:28     ` __attribute__((unused)) Maciej W. Rozycki
@ 2004-10-15 12:31     ` Alan Cox
  2004-10-15 13:50       ` __attribute__((unused)) Richard B. Johnson
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Cox @ 2004-10-15 12:31 UTC (permalink / raw)
  To: Russell King; +Cc: David Woodhouse, Linux Kernel Mailing List

On Iau, 2004-10-14 at 23:08, Russell King wrote:
> It's the "later compilers" which I'm worried about here - I think they
> defined "unused" to mean "this really really isn't used and you can
> discard it".  Hence my concern with the above.

This was the explanation I got some time ago

-- quote --

So "used" cases that used "unused" could break, though older compilers
in essence used "unused" to mean both "used" and "unused".  Since
"unused" becomes useless for using in "used" cases, we now must be sure
to use "used" when that's the use that's useful.
			-- Roland McGrath


I found it so helpful it became a .sig 8)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-14 21:02 __attribute__((unused)) Russell King
  2004-10-14 22:04 ` __attribute__((unused)) David Woodhouse
@ 2004-10-15 12:33 ` Frank van Maarseveen
  2004-10-15 13:15   ` __attribute__((unused)) Maciej W. Rozycki
  1 sibling, 1 reply; 8+ messages in thread
From: Frank van Maarseveen @ 2004-10-15 12:33 UTC (permalink / raw)
  To: Linux Kernel List

On Thu, Oct 14, 2004 at 10:02:43PM +0100, Russell King wrote:
> 
> I notice that module.h contains stuff like:
> 
> #define MODULE_GENERIC_TABLE(gtype,name)                        \
> extern const struct gtype##_id __mod_##gtype##_table            \
>   __attribute__ ((unused, alias(__stringify(name))))
> 
> and even:
> 
> #define __MODULE_INFO(tag, name, info)                                    \
> static const char __module_cat(name,__LINE__)[]                           \
>   __attribute_used__                                                      \
>   __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
> 
> My understanding is that we shouldn't be using __attribute__((unused))
> in either of these - can someone confirm.
> 
> The second one looks fairly dodgy since we're telling a compiler that
> it's both used and unused.  That sounds a bit like a HHGTTG puzzle (you
> have tea and no tea.)

This makes sense, assuming the gcc info pages are correct:
`unused'
     This attribute, attached to a function, means that the function is
     meant to be possibly unused.  GCC will not produce a warning for
     this function.  GNU C++ does not currently support this attribute
     as definitions without parameters are valid in C++.

`used'
     This attribute, attached to a function, means that code must be
     emitted for the function even if it appears that the function is
     not referenced.  This is useful, for example, when the function is
     referenced only in inline assembly.

So, a function could be "used" and "unused" at the same time:

	unused -> don't warn
	used -> don't discard

-- 
Frank

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-15 12:33 ` __attribute__((unused)) Frank van Maarseveen
@ 2004-10-15 13:15   ` Maciej W. Rozycki
  0 siblings, 0 replies; 8+ messages in thread
From: Maciej W. Rozycki @ 2004-10-15 13:15 UTC (permalink / raw)
  To: Frank van Maarseveen; +Cc: Linux Kernel List

On Fri, 15 Oct 2004, Frank van Maarseveen wrote:

> This makes sense, assuming the gcc info pages are correct:
> `unused'
>      This attribute, attached to a function, means that the function is
>      meant to be possibly unused.  GCC will not produce a warning for
>      this function.  GNU C++ does not currently support this attribute
>      as definitions without parameters are valid in C++.
> 
> `used'
>      This attribute, attached to a function, means that code must be
>      emitted for the function even if it appears that the function is
>      not referenced.  This is useful, for example, when the function is
>      referenced only in inline assembly.
> 
> So, a function could be "used" and "unused" at the same time:
> 
> 	unused -> don't warn
> 	used -> don't discard

 Except that "used" already implies no warning as it makes the function 
not unused anymore.

  Maciej

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: __attribute__((unused))
  2004-10-15 12:31     ` __attribute__((unused)) Alan Cox
@ 2004-10-15 13:50       ` Richard B. Johnson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard B. Johnson @ 2004-10-15 13:50 UTC (permalink / raw)
  To: Alan Cox; +Cc: Russell King, David Woodhouse, Linux Kernel Mailing List

On Fri, 15 Oct 2004, Alan Cox wrote:

> On Iau, 2004-10-14 at 23:08, Russell King wrote:
>> It's the "later compilers" which I'm worried about here - I think they
>> defined "unused" to mean "this really really isn't used and you can
>> discard it".  Hence my concern with the above.
>
> This was the explanation I got some time ago
>
> -- quote --
>
> So "used" cases that used "unused" could break, though older compilers
> in essence used "unused" to mean both "used" and "unused".  Since
> "unused" becomes useless for using in "used" cases, we now must be sure
> to use "used" when that's the use that's useful.
> 			-- Roland McGrath
>
>
> I found it so helpful it became a .sig 8)
>
Yes. Just like "less" is more than "more"......and whos on first base.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.8 on an i686 machine (5537.79 BogoMips).
             Note 96.31% of all statistics are fiction.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-10-15 13:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-14 21:02 __attribute__((unused)) Russell King
2004-10-14 22:04 ` __attribute__((unused)) David Woodhouse
2004-10-14 22:08   ` __attribute__((unused)) Russell King
2004-10-14 23:28     ` __attribute__((unused)) Maciej W. Rozycki
2004-10-15 12:31     ` __attribute__((unused)) Alan Cox
2004-10-15 13:50       ` __attribute__((unused)) Richard B. Johnson
2004-10-15 12:33 ` __attribute__((unused)) Frank van Maarseveen
2004-10-15 13:15   ` __attribute__((unused)) Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox