public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/106571] New: Implement -Wsection diag
@ 2022-08-09 11:36 bp at alien8 dot de
  2022-08-09 17:01 ` [Bug c/106571] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bp at alien8 dot de @ 2022-08-09 11:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

            Bug ID: 106571
           Summary: Implement -Wsection diag
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bp at alien8 dot de
  Target Milestone: ---

Hi,

clang has this -Wsection diag which does:

https://clang.llvm.org/docs/DiagnosticsReference.html#wsection

It would be good to have it in gcc too so that declarations like

extern u64 x86_spec_ctrl_current;

for variable definitions which belong to a specific section:

__attribute__((section(".data..percpu" ""))) __typeof__(u64)
x86_spec_ctrl_current;

get caught:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on
redeclared variable [-Werror,-Wsection]

Thx.

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

* [Bug c/106571] Implement -Wsection diag
  2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
@ 2022-08-09 17:01 ` pinskia at gcc dot gnu.org
  2022-08-09 17:08 ` bp at alien8 dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-09 17:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-08-09
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |WAITING
          Component|other                       |c

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This example seems not to be correct as this is section is not needed on the
declaration only the definition.

If this is the example, I think the warning is incorrect and should not be
implemented in GCC.

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

* [Bug c/106571] Implement -Wsection diag
  2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
  2022-08-09 17:01 ` [Bug c/106571] " pinskia at gcc dot gnu.org
@ 2022-08-09 17:08 ` bp at alien8 dot de
  2022-08-09 17:30 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bp at alien8 dot de @ 2022-08-09 17:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

--- Comment #2 from Boris <bp at alien8 dot de> ---
How can you check a mismatch if only the definition has the section attribute?

Here's the kernel commit which fixes this for clang:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=db886979683a8360ced9b24ab1125ad0c4d2cf76

there's the same example in the commit message.

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

* [Bug c/106571] Implement -Wsection diag
  2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
  2022-08-09 17:01 ` [Bug c/106571] " pinskia at gcc dot gnu.org
  2022-08-09 17:08 ` bp at alien8 dot de
@ 2022-08-09 17:30 ` pinskia at gcc dot gnu.org
  2022-08-10 11:57 ` matz at gcc dot gnu.org
  2022-08-10 15:11 ` bp at alien8 dot de
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-09 17:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Boris from comment #2)
> How can you check a mismatch if only the definition has the section
> attribute?

You don't need to.

> 
> Here's the kernel commit which fixes this for clang:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/
> ?id=db886979683a8360ced9b24ab1125ad0c4d2cf76
> 
> there's the same example in the commit message.

Oh I see the section here has more semantics than the normal section attribute
does. There should be an enhancement request for a new attribute which does
more than the current section attribute instead.

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

* [Bug c/106571] Implement -Wsection diag
  2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
                   ` (2 preceding siblings ...)
  2022-08-09 17:30 ` pinskia at gcc dot gnu.org
@ 2022-08-10 11:57 ` matz at gcc dot gnu.org
  2022-08-10 15:11 ` bp at alien8 dot de
  4 siblings, 0 replies; 6+ messages in thread
From: matz at gcc dot gnu.org @ 2022-08-10 11:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

Michael Matz <matz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matz at gcc dot gnu.org

--- Comment #4 from Michael Matz <matz at gcc dot gnu.org> ---
To elaborate: normally you don't need to know which section a variable will be
placed into when generating code to access it.  (In fact you don't even need to
know if it's defined in the same linking component at all)

So, for declarations the section is immaterial, and checking for a mismatch
between decl and def doesn't seem appropriate.  In the general case.  This is
not
the general case, the per-cpu sections of the kernel have special semantics,
and I agree with Andrew that checking would be better implemented with
something
orthogonal to the section attribute itself.

Boris: what does DECLARE_PER_CPU() expand into?  Are there other attributes
that could be usefully checked for mismatch between decl and def?

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

* [Bug c/106571] Implement -Wsection diag
  2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
                   ` (3 preceding siblings ...)
  2022-08-10 11:57 ` matz at gcc dot gnu.org
@ 2022-08-10 15:11 ` bp at alien8 dot de
  4 siblings, 0 replies; 6+ messages in thread
From: bp at alien8 dot de @ 2022-08-10 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106571

--- Comment #5 from Boris <bp at alien8 dot de> ---
(In reply to Michael Matz from comment #4)
> Boris: what does DECLARE_PER_CPU() expand into?  Are there other attributes
> that could be usefully checked for mismatch between decl and def?

Unfortunately,

DECLARE_PER_CPU(u64, x86_spec_ctrl_current);

expands only to:

extern __attribute__((section(".data..percpu" ""))) __typeof__(u64)
x86_spec_ctrl_current;

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

end of thread, other threads:[~2022-08-10 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 11:36 [Bug other/106571] New: Implement -Wsection diag bp at alien8 dot de
2022-08-09 17:01 ` [Bug c/106571] " pinskia at gcc dot gnu.org
2022-08-09 17:08 ` bp at alien8 dot de
2022-08-09 17:30 ` pinskia at gcc dot gnu.org
2022-08-10 11:57 ` matz at gcc dot gnu.org
2022-08-10 15:11 ` bp at alien8 dot de

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 read-only IMAP folder(s) and NNTP newsgroup(s).