From: Lancelot SIX <Lancelot.Six@amd.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python/python-internal.h: avoid uninitialized constexpr
Date: Wed, 19 Jun 2024 10:16:27 +0100 [thread overview]
Message-ID: <6c29a247-3b9c-4562-a4ff-1a0f502f647a@amd.com> (raw)
In-Reply-To: <87jzilyeo6.fsf@tromey.com>
On 19/06/2024 01:11, Tom Tromey wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
>
>
>>>>>> "Lancelot" == Lancelot SIX <Lancelot.Six@amd.com> writes:
>
> Lancelot> That works with GCC, but still fails with Clang. I still have
> Lancelot> duplicate symbol errors (both at -O0 and -O3). My understanding is
> Lancelot> that the compiler can still handle constexr as const if it wants, so
> Lancelot> marking those symbols constexpr will not necessarily prevent them from
> Lancelot> being materialized in the binary.
>
> Which symbol is duplicate?
All the specialized instantiations appear as duplicates.
With your solution, if I compile with GCC, I have:
$ nm -C gdb/python/py-arch.o|grep gdbpy_method_format
0000000000000380 r gdbpy_method_format<int>
00000000000003c0 r gdbpy_method_format<unsigned int>
0000000000000300 r gdbpy_method_format<long long>
0000000000000340 r gdbpy_method_format<unsigned long long>
while when compiling with clang:
$ nm -C gdb/python/py-arch.o|grep gdbpy_method_format
0000000000000040 R gdbpy_method_format<int>
0000000000000060 R gdbpy_method_format<unsigned int>
0000000000000000 R gdbpy_method_format<long long>
0000000000000020 R gdbpy_method_format<unsigned long long>
It looks like clang picks the "extern" qualifier from the
non-specialized case, and applies it to all the specializations.
It seems I can avoid this by marking the specializations as inline, i.e.
template<typename T>
extern char gdbpy_method_format;
template<>
constexpr inline char gdbpy_method_format<gdb_py_longest> =
GDB_PY_LL_ARG[0];
...
This approach seems to work for both clang and gcc. I can modify my
patch to use this method if you prefer.
>
> Anyway if that is the case, then why does your patch work?
>
In my approach, it seems the symbol is not be present in the object
files for neither gcc or clang. If I force it (by taking the address of
the symbol for example), nm reports the symbol as a weak object ("V")
for clang and "u" for gcc.
Best,
Lancelot.
next prev parent reply other threads:[~2024-06-19 9:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 9:09 Lancelot SIX
2024-06-18 13:00 ` Tom de Vries
2024-06-18 15:25 ` Tom de Vries
2024-06-18 16:17 ` Tom Tromey
2024-06-18 18:27 ` Lancelot SIX
2024-06-18 19:48 ` Tom Tromey
2024-06-18 21:01 ` Lancelot SIX
2024-06-18 21:03 ` Tom Tromey
2024-06-18 21:26 ` Lancelot SIX
2024-06-19 0:11 ` Tom Tromey
2024-06-19 9:16 ` Lancelot SIX [this message]
2024-06-19 13:41 ` Tom Tromey
2024-06-19 14:29 ` Lancelot SIX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c29a247-3b9c-4562-a4ff-1a0f502f647a@amd.com \
--to=lancelot.six@amd.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox