I'm trying to put a specific set of functions into a separate section and got trouble doing it with GCC.
namespace /* anonymous */ {
[[gnu::section(".mysection")]]
void regular_func() { }
template <class T>
[[gnu::section(".mysection")]]
void template_func() { }
} // namespace /* anonymous */
void (*ptr1)() = ®ular_func;
void (*ptr2)() = &template_func<int>;
With clang, the symbols for both of regular_func
and template_func<int>
are placed in .mysection
as I expected.
$ clang++ -std=c++14 a.cpp -c && objdump -t a.o | grep -E "regular|template"
0000000000000000 l F .mysection 0000000000000006 _ZN12_GLOBAL__N_112regular_funcEv
0000000000000010 l F .mysection 0000000000000006 _ZN12_GLOBAL__N_113template_funcIiEEvv
But with GCC, the function template is not placed in .mysection
, but in the .text.*
section.
$ g++ -std=c++14 a.cpp -c && objdump -t a.o | grep -E "regular|template"
0000000000000000 l F .mysection 0000000000000007 _ZN12_GLOBAL__N_112regular_funcEv
0000000000000000 l F .text 0000000000000007 _ZN12_GLOBAL__N_113template_funcIiEEvv
I'm using clang-3.7.1 and gcc-5.3.0.
How can I force gcc to put the template-instantiated function in a separate section?
Aucun commentaire:
Enregistrer un commentaire