mbox series

[v3,00/14] treewide: prefer __section from compiler_attributes.h

Message ID 20190828225535.49592-1-ndesaulniers@google.com
Headers show
Series treewide: prefer __section from compiler_attributes.h | expand

Message

Nick Desaulniers Aug. 28, 2019, 10:55 p.m. UTC
GCC unescapes escaped string section names while Clang does not. Because
__section uses the `#` stringification operator for the section name, it
doesn't need to be escaped.

This fixes an Oops observed in distro's that use systemd and not
net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.

Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section__(".section"))) when creating the
section name via C preprocessor (see the definition of __define_initcall
in arch/um/include/shared/init.h).

This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r

See the discussions in:
https://bugs.llvm.org/show_bug.cgi?id=42950
https://marc.info/?l=linux-netdev&m=156412960619946&w=2
https://github.com/ClangBuiltLinux/linux/issues/619

Changes V2 -> V3:
* s/__attribute__((__section/__attribute__((__section__ in commit
  messages as per Joe.
Changes V1 -> V2:
* drop arm64, arc, and sh patches as they were picked up by their
  maintainers.
* Split the previous V1 hunk from include/linux that touched
  include/linux/compiler.h off into its own patch for inclusion in
  stable, as it fixes a user visible issue.
* Collect Acks and Tested by tags.

Nick Desaulniers (14):
  s390/boot: fix section name escaping
  include/linux/compiler.h: prefer __section from compiler_attributes.h
  parisc: prefer __section from compiler_attributes.h
  um: prefer __section from compiler_attributes.h
  ia64: prefer __section from compiler_attributes.h
  arm: prefer __section from compiler_attributes.h
  mips: prefer __section from compiler_attributes.h
  sparc: prefer __section from compiler_attributes.h
  powerpc: prefer __section and __printf from compiler_attributes.h
  x86: prefer __section from compiler_attributes.h
  include/asm-generic: prefer __section from compiler_attributes.h
  include/linux: prefer __section from compiler_attributes.h
  include/linux/compiler.h: remove unused KENTRY macro
  compiler_attributes.h: add note about __section

 arch/arm/include/asm/cache.h          |  2 +-
 arch/arm/include/asm/mach/arch.h      |  4 ++--
 arch/arm/include/asm/setup.h          |  2 +-
 arch/ia64/include/asm/cache.h         |  2 +-
 arch/mips/include/asm/cache.h         |  2 +-
 arch/parisc/include/asm/cache.h       |  2 +-
 arch/parisc/include/asm/ldcw.h        |  2 +-
 arch/powerpc/boot/main.c              |  3 +--
 arch/powerpc/boot/ps3.c               |  6 ++----
 arch/powerpc/include/asm/cache.h      |  2 +-
 arch/powerpc/kernel/btext.c           |  2 +-
 arch/s390/boot/startup.c              |  2 +-
 arch/sparc/include/asm/cache.h        |  2 +-
 arch/sparc/kernel/btext.c             |  2 +-
 arch/um/kernel/um_arch.c              |  6 +++---
 arch/x86/include/asm/cache.h          |  2 +-
 arch/x86/include/asm/intel-mid.h      |  2 +-
 arch/x86/include/asm/iommu_table.h    |  5 ++---
 arch/x86/include/asm/irqflags.h       |  2 +-
 arch/x86/include/asm/mem_encrypt.h    |  2 +-
 arch/x86/kernel/cpu/cpu.h             |  3 +--
 include/asm-generic/error-injection.h |  2 +-
 include/asm-generic/kprobes.h         |  5 ++---
 include/linux/cache.h                 |  6 +++---
 include/linux/compiler.h              | 31 ++++-----------------------
 include/linux/compiler_attributes.h   | 10 +++++++++
 include/linux/cpu.h                   |  2 +-
 include/linux/export.h                |  2 +-
 include/linux/init_task.h             |  4 ++--
 include/linux/interrupt.h             |  5 ++---
 include/linux/sched/debug.h           |  2 +-
 include/linux/srcutree.h              |  2 +-
 32 files changed, 54 insertions(+), 74 deletions(-)

-- 
2.23.0.187.g17f5b7556c-goog

Comments

Miguel Ojeda Aug. 29, 2019, 8:24 p.m. UTC | #1
On Thu, Aug 29, 2019 at 12:55 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>

> Changes V2 -> V3:

> * s/__attribute__((__section/__attribute__((__section__ in commit

>   messages as per Joe.


I have uploaded to -next v3 so that we get some feedback tomorrow
rather than waiting for Monday.

I added a few changes, please take a look at the commits:

  https://github.com/ojeda/linux/commits/compiler-attributes

and let me know if you agree (look for the [...] text before my
signature). Specially this one since it is the one I re-added the
unused attribute as __maybe_unused:

  https://github.com/ojeda/linux/commit/a103a32ac6a2c8bbb8fb217af92c9f6bd08e138c

Cheers,
Miguel
Sedat Dilek Aug. 29, 2019, 8:37 p.m. UTC | #2
On Thu, Aug 29, 2019 at 10:24 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>

> On Thu, Aug 29, 2019 at 12:55 AM Nick Desaulniers

> <ndesaulniers@google.com> wrote:

> >

> > Changes V2 -> V3:

> > * s/__attribute__((__section/__attribute__((__section__ in commit

> >   messages as per Joe.

>

> I have uploaded to -next v3 so that we get some feedback tomorrow

> rather than waiting for Monday.

>

> I added a few changes, please take a look at the commits:

>

>   https://github.com/ojeda/linux/commits/compiler-attributes

>


Thanks for taking care and bringing this to linux-next asap.

- Sedat -
Nick Desaulniers Aug. 29, 2019, 8:47 p.m. UTC | #3
On Thu, Aug 29, 2019 at 1:37 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>

> On Thu, Aug 29, 2019 at 10:24 PM Miguel Ojeda

> <miguel.ojeda.sandonis@gmail.com> wrote:

> >

> > On Thu, Aug 29, 2019 at 12:55 AM Nick Desaulniers

> > <ndesaulniers@google.com> wrote:

> > >

> > > Changes V2 -> V3:

> > > * s/__attribute__((__section/__attribute__((__section__ in commit

> > >   messages as per Joe.

> >

> > I have uploaded to -next v3 so that we get some feedback tomorrow

> > rather than waiting for Monday.

> >

> > I added a few changes, please take a look at the commits:

> >

> >   https://github.com/ojeda/linux/commits/compiler-attributes

> >

>

> Thanks for taking care and bringing this to linux-next asap.


LGTM, thanks Miguel, ship it!

-- 
Thanks,
~Nick Desaulniers