public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: 程智星 <zhixing@nj.iscas.ac.cn>
To: binutils@sourceware.org
Subject: binutils for musl
Date: Wed, 12 Jul 2023 14:29:41 +0800 (GMT+08:00)	[thread overview]
Message-ID: <6002ef10.1bdab.18948ca8d90.Coremail.zhixing@nj.iscas.ac.cn> (raw)


[-- 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),


             reply	other threads:[~2023-07-12  6:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12  6:29 程智星 [this message]
2023-07-12  9:05 ` Alan Modra

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=6002ef10.1bdab.18948ca8d90.Coremail.zhixing@nj.iscas.ac.cn \
    --to=zhixing@nj.iscas.ac.cn \
    --cc=binutils@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).