binutils for musl

程智星 zhixing@nj.iscas.ac.cn
Wed Jul 12 06:29:41 GMT 2023


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!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: use-static_cast.patch
Type: application/octet-stream
Size: 1016 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20230712/a634a1ee/attachment.obj>


More information about the Binutils mailing list