* binutils for musl
@ 2023-07-12 6:29 程智星
2023-07-12 9:05 ` Alan Modra
0 siblings, 1 reply; 2+ messages in thread
From: 程智星 @ 2023-07-12 6:29 UTC (permalink / raw)
To: binutils
[-- Attachment #1.1: Type: text/plain, Size: 1345 bytes --]
hi,friend:
When I use Musl as the base library to compile the yocto embedded system, the following error will be reported:
= {anonymous}::Target_i386; Scan = {anonymous}::Target_i386::Scan; Classify_reloc = {anonymous}::Target_i386::Classify_reloc; size_t = long unsigned int]':
| ../../gold/i386.cc:2624:19: required from here
| ../../gold/gc.h:250:34: error: invalid cast from type 'std::nullptr_t' to type 'gold::Relobj*'
| 250 | (*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
| | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ../../gold/gc.h:332:34: error: invalid cast from type 'std::nullptr_t' to type 'gold::Relobj*'
| 332 | (*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
I think the reason for this problem is:
In glibc, NULL is defined as (void *) 0, so reinterpret_cast is used When performs Type conversion, it is legal to convert NULL to Relobj *. But in Musl, NULL is defined as nullptr, while reinterpret_cast is not safe for cast to convert nullptr to a specific pointer type, so compilation will report an error.
So I used static_cast Replace reinterpret_cast , specific patch as attached; can this be integrated into our source code? Or do you have a better solution to address this error?
Looking forward to your reply!
[-- Attachment #2: use-static_cast.patch --]
[-- Type: application/octet-stream, Size: 1016 bytes --]
diff --git a/gold/gc.h b/gold/gc.h
index 6ebd81f3fd0..4a1368f5abe 100644
--- a/gold/gc.h
+++ b/gold/gc.h
@@ -247,7 +247,7 @@ gc_process_relocs(
if (is_ordinary)
(*secvec).push_back(Section_id(src_obj, dst_indx));
else
- (*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
+ (*secvec).push_back(Section_id(static_cast<Relobj*>(NULL), 0));
// If the target of the relocation is an STT_SECTION symbol,
// make a note of that by storing -1 in the symbol vector.
if (lsym.get_st_type() == elfcpp::STT_SECTION)
@@ -329,7 +329,7 @@ gc_process_relocs(
if (is_ordinary && dst_obj != NULL)
(*secvec).push_back(Section_id(dst_obj, dst_indx));
else
- (*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
+ (*secvec).push_back(Section_id(static_cast<Relobj*>(NULL), 0));
(*symvec).push_back(gsym);
(*addendvec).push_back(std::make_pair(
static_cast<long long>(symvalue),
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: binutils for musl
2023-07-12 6:29 binutils for musl 程智星
@ 2023-07-12 9:05 ` Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2023-07-12 9:05 UTC (permalink / raw)
To: 程智星; +Cc: binutils
On Wed, Jul 12, 2023 at 02:29:41PM +0800, 程智星 wrote:
> hi,friend:
>
> When I use Musl as the base library to compile the yocto embedded system, the following error will be reported:
>
> = {anonymous}::Target_i386; Scan = {anonymous}::Target_i386::Scan; Classify_reloc = {anonymous}::Target_i386::Classify_reloc; size_t = long unsigned int]':
>
> | ../../gold/i386.cc:2624:19: required from here
>
> | ../../gold/gc.h:250:34: error: invalid cast from type 'std::nullptr_t' to type 'gold::Relobj*'
>
> | 250 | (*secvec).push_back(Section_id(reinterpret_cast<Relobj*>(NULL), 0));
>
> | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This was fixed in git commit b97bd976233e, with the same patch you
posted.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-12 9:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 6:29 binutils for musl 程智星
2023-07-12 9:05 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).