diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-03-10 10:38:49 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-03-10 10:38:49 +0100 |
commit | 4c599ae6e081496466cada6f97b0d4687a6d765a (patch) | |
tree | 03a7d763a1acd563aaafbf6a019bfdc5cda85c93 /gcc/tree.cc | |
parent | 2eb0191aa104badf3cab127f7f87d371c0fef92b (diff) | |
download | gcc-4c599ae6e081496466cada6f97b0d4687a6d765a.zip gcc-4c599ae6e081496466cada6f97b0d4687a6d765a.tar.gz gcc-4c599ae6e081496466cada6f97b0d4687a6d765a.tar.bz2 |
tree: Use comdat tree_code_{type,length} even for C++11/14 [PR108634]
The recent change to undo the tree_code_type/tree_code_length
excessive duplication apparently broke building the Linux kernel
plugin. While it is certainly desirable that GCC plugins are built
with the same compiler as GCC has been built and with the same options
(at least the important ones), it might be hard to arrange that,
e.g. if gcc is built using a cross-compiler but the plugin then built
natively, or GCC isn't bootstrapped for other reasons, or just as in
the kernel case they were building the plugin with -std=gnu++11 while
the bootstrapped GCC has been built without any such option and so with
whatever the compiler defaulted to.
For C++17 and later tree_code_{type,length} are UNIQUE symbols with
those assembler names, while for C++11/14 they were
_ZL14tree_code_type and _ZL16tree_code_length.
The following patch uses a comdat var for those even for C++11/14
as suggested by Maciej Cencora. Relying on weak attribute is not an
option because not all hosts support it and there are non-GNU system
compilers. While we could use it unconditionally,
I think defining a template just to make it comdat is weird, and
the compiler itself is always built with the same compiler.
Plugins, being separate shared libraries, will have a separate copy of
the arrays if they are ODR-used in the plugin, so there is not a big
deal if e.g. cc1plus uses tree_code_type while plugin uses
_ZN19tree_code_type_tmplILi0EE14tree_code_typeE or vice versa.
2023-03-10 Jakub Jelinek <jakub@redhat.com>
PR plugins/108634
* tree-core.h (tree_code_type, tree_code_length): For C++11 or
C++14, don't declare as extern const arrays.
(tree_code_type_tmpl, tree_code_length_tmpl): New types with
static constexpr member arrays for C++11 or C++14.
* tree.h (TREE_CODE_CLASS): For C++11 or C++14 use
tree_code_type_tmpl <0>::tree_code_type instead of tree_code_type.
(TREE_CODE_LENGTH): For C++11 or C++14 use
tree_code_length_tmpl <0>::tree_code_length instead of
tree_code_length.
* tree.cc (tree_code_type, tree_code_length): Remove.
Diffstat (limited to 'gcc/tree.cc')
-rw-r--r-- | gcc/tree.cc | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/gcc/tree.cc b/gcc/tree.cc index 41ccbf3..d17106e 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -74,34 +74,6 @@ along with GCC; see the file COPYING3. If not see #include "asan.h" #include "ubsan.h" -#if __cpp_inline_variables < 201606L -/* Tree code classes. */ - -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, -#define END_OF_BASE_TREE_CODES tcc_exceptional, - -const enum tree_code_class tree_code_type[] = { -#include "all-tree.def" -}; - -#undef DEFTREECODE -#undef END_OF_BASE_TREE_CODES - -/* Table indexed by tree code giving number of expression - operands beyond the fixed part of the node structure. - Not used for types or decls. */ - -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, -#define END_OF_BASE_TREE_CODES 0, - -const unsigned char tree_code_length[] = { -#include "all-tree.def" -}; - -#undef DEFTREECODE -#undef END_OF_BASE_TREE_CODES -#endif - /* Names of tree components. Used for printing out the tree and error messages. */ #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, |