bebbo / libnix

libnix (v4): a C link library for AmigaOS/m68k
15 stars 9 forks source link

Element type of struct dirent.d_name should be char, not BYTE #1

Closed th-otto closed 5 years ago

th-otto commented 5 years ago

BYTE is defined explicitly as "signed char". Using strcpy on such a type gives a warning, and when using C++ it gives an error:

$ cat foo.cc
#include <dirent.h>
#include <string>

struct dirent *d;

int main(void)
{
        std::string s;
        s = d->d_name;
        return 0;
}

$ m68k-amigaos-g++ -mcrt=nix20 foo.cc
foo.cc: In function 'int main()':
foo.cc:9:9: error: ambiguous overload for 'operator=' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'BYTE [256] {aka signed char [256]}')
  s = d->d_name;
         ^~~~~~
In file included from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/string:52:0,
                 from foo.cc:2:
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/basic_string.h:604:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
       operator=(const _CharT* __s)
       ^~~~~~~~
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/basic_string.h:604:7: note:   conversion of argument 1 would be ill-formed:
foo.cc:9:9: error: invalid conversion from 'BYTE* {aka signed char*}' to 'const char*' [-fpermissive]
  s = d->d_name;
      ~~~^~~~~~
In file included from /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/string:52:0,
                 from foo.cc:2:
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/basic_string.h:615:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
       operator=(_CharT __c)
       ^~~~~~~~
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/include/c++/bits/basic_string.h:615:7: note:   conversion of argument 1 would be ill-formed:
foo.cc:9:9: error: invalid conversion from 'BYTE* {aka signed char*}' to 'char' [-fpermissive]
  s = d->d_name;
      ~~~^~~~~~
bebbo commented 5 years ago

please test

th-otto commented 5 years ago

The actual patch looks good to me, but when updating i now get

make[2]: Entering directory '/home/sebilla/amiga/amiga-gcc/build-Linux/libnix/startup'
make[2]: *** No rule to make target 'nrcrt0.S', needed by 'nrcrt0.o'.  Stop.
bebbo commented 5 years ago

did u miss a git pull ?

th-otto commented 5 years ago

Oops, yes. I thought "make update" would do that.

Looks good.

bebbo commented 5 years ago

Oops, yes. I thought "make update" would do that.

Looks good.

A change of the Makefile would only be active with the next call, if it updates itself...

arczi84 commented 5 years ago

Make still have problem finding nrcrt0.S libnix/startup which is empty

make[2]: Entering directory '/e/src/libnix/startup' make[2]: *** No rule to make target 'nrcrt0.S', needed by 'nrcrt0.o'. Stop.

It's in /e/src/libnix/sources/startup

My config: ./configure TARGET=m68k-amigaos --with-cross-host=x86_64-pc-cygwin --host=m68k-amigaos --prefix=/e/usr/local/amiga/m68k-amigaos CXX="m68k-amigaos-g++" CC="m68k-amigaos-gcc" --srcdir=.

bebbo commented 5 years ago

consider using Makefile.gcc6

arczi84 commented 5 years ago

Can I compile it for a.out format with gcc6 ?

bebbo commented 5 years ago

*.S files are there again - undid the rename. So the old crappy configure/make should work again.

Or try the newer (more crappy) Makefile.gcc6

Can I compile it for a.out format with gcc6 ?

That's the assemblers job. If there is no usable m68k-amigaos-as you might switch over to alpines branch using vasm.

arczi84 commented 5 years ago

Now it compiles with gcc6 makefile, but stops on

/src/libnix/sources/startup/libinitr.c:187: error: syntax error before "void"

arczi84 commented 5 years ago

So if I just use a.out 'as' compiler it will end in a.out format ?

bebbo commented 5 years ago

So if I just use a.out 'as' compiler it will end in a.out format ?

with the appropriate assembler you'll get a.out. Just do the steps by hand:

arczi84 commented 5 years ago

Is __entrypoint a gcc6 thing ?

bebbo commented 5 years ago

Is __entrypoint a gcc6 thing ?

yes - it tells the compiler to omit reg saves.

arczi84 commented 5 years ago

How to treat it in older compiler?

bebbo commented 5 years ago

in libinitr.c it's not necessary... ... stackswap.c needs it

guess you have to replace it with pure asm code for older gcc's.