[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190828225535.49592-15-ndesaulniers@google.com>
Date: Wed, 28 Aug 2019 15:55:35 -0700
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: miguel.ojeda.sandonis@...il.com
Cc: sedat.dilek@...il.com, will@...nel.org, jpoimboe@...hat.com,
naveen.n.rao@...ux.vnet.ibm.com, davem@...emloft.net,
paul.burton@...s.com, clang-built-linux@...glegroups.com,
linux-kernel@...r.kernel.org,
Nick Desaulniers <ndesaulniers@...gle.com>
Subject: [PATCH v3 14/14] compiler_attributes.h: add note about __section
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.
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:
Link: https://bugs.llvm.org/show_bug.cgi?id=42950
Link: https://marc.info/?l=linux-netdev&m=156412960619946&w=2
Link: https://github.com/ClangBuiltLinux/linux/issues/619
Tested-by: Sedat Dilek <sedat.dilek@...il.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@...gle.com>
---
include/linux/compiler_attributes.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index 6b318efd8a74..f8c008d7f616 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -225,6 +225,16 @@
#define __pure __attribute__((__pure__))
/*
+ * Note: Since this macro makes use of the "stringification operator" `#`, a
+ * quoted string literal should not be passed to it. eg.
+ * prefer:
+ * __section(.foo)
+ * to:
+ * __section(".foo")
+ * unless the section name is dynamically built up, in which case the
+ * verbose __attribute__((__section__(".foo" x))) should be preferred.
+ * See also: https://bugs.llvm.org/show_bug.cgi?id=42950
+ *
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute
* clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate
--
2.23.0.187.g17f5b7556c-goog
Powered by blists - more mailing lists