freemint / m68k-atari-mint-gcc

Fork of GNU's gcc with support for the m68k-atari-mint target
https://github.com/freemint/m68k-atari-mint-gcc/wiki
Other
26 stars 7 forks source link

stdatomic.h not usable #16

Closed th-otto closed 1 year ago

th-otto commented 2 years ago

While compiling a newer version of opensll, i stumbled upon the problem that stdatomic.h was used, and caused compile errors. Reason is that our port did not define the builtin __INT_LEAST* macros, because of lack of a target specific stdint.h file. I've added that now to my port, see https://github.com/th-otto/m68k-atari-mint-gcc/commit/07e391687954f7a4ec0cfa99ab2ad2dad5b4cc6f

Another fix: there was a call to init_sync_libfuncs missing, causing those functions to emit library calls to __atomic_add* etc, which do not exist in libgcc.a. Fixed with commit https://github.com/th-otto/m68k-atari-mint-gcc/commit/5e3d122dc5e80da34e1726475856c379d745e248

This relies on a commit i did already earlier to add the syncfetch functions to libgcc.a, in https://github.com/th-otto/m68k-atari-mint-gcc/commit/5ce7a5902a42ba75a63f261a5f78cfadf76036a1

Maybe you want to take a look at these, and implement them here, too.

mikrosk commented 1 year ago

@th-otto I've used the openssl build script/patch on your website and tried to compile it with gcc-7-mint without these two commits. All went fine because you disabled #include <stdatomic.h> in your patch. Then I removed the stdatomic stuff from your patch and tried again. As expected, the build failed.

Then I switched to gcc-13-mintelf (which contains only the first commit) and tried again (already without the stdatomic stuff in your patch) and indeed, I could see the linker errors instead of missing constants. After applying your second commit (out of paranoia including the rename change, see https://github.com/th-otto/m68k-atari-mint-gcc/commit/5e3d122dc5e80da34e1726475856c379d745e248#commitcomment-124482977) I was expecting to compile it flawlessly but unfortunately, this was not the case.

So I switched back to gcc-7-mint and applied both commits as is (as none of them were present in that branch). And unfortunately, this doesn't work either: I see a lot of missing references to _sync_add_and_fetch4, sync_sub_and_fetch_4, ___sync_fetch_and_add_4 and maybe a few others.

Can you try either branch (gcc-13-mintelf or gcc-7-mint) whether those two commits are really the only missing pieces to get openssl's std::atomic functionality working?

Btw while compiling with gcc-13-mintelf, I could see some interesting error messages (@vinriviere):

/home/mikro/gnu-tools-elf/m68000/lib/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: /home/mikro/gnu-tools-elf/m68000/m68k-atari-mintelf/sys-root/usr/lib/libc.a(syslog.o):(.bss+0x0): multiple definition of `_errno'; /home/mikro/gnu-tools-elf/m68000/m68k-atari-mintelf/sys-root/usr/lib/libc.a(errno.o):(.bss+0x0): first defined here
/home/mikro/gnu-tools-elf/m68000/lib/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: warning: xfgnulib.o: missing .note.GNU-stack section implies executable stack

(not present while compiling with gcc-7-mint)

mikrosk commented 1 year ago

Damn it, I have totally overlooked the third commit:

This relies on a commit i did already earlier to add the syncfetch functions to libgcc.a, in https://github.com/th-otto/m68k-atari-mint-gcc/commit/5ce7a5902a42ba75a63f261a5f78cfadf76036a1

:D

Ok, disregard the previous post.

mikrosk commented 1 year ago

Now that I have applied all three commits I can confirm that gcc-7-mint compiles openssl as expected. I have pushed them to gcc-7-mint branch.

But, the other issues with gcc-13-mintelf were not a random glitch:

${LDCMD:-m68k-atari-mintelf-gcc -m68020-60} -Wa,--noexecstack -Wall -O3 -fomit-frame-pointer -L. -s  \
        -o apps/openssl apps/asn1pars.o apps/ca.o apps/ciphers.o apps/cms.o apps/crl.o apps/crl2p7.o apps/dgst.o apps/dhparam.o apps/dsa.o apps/dsaparam.o apps/ec.o apps/ecparam.o apps/enc.o apps/engine.o apps/errstr.o apps/gendsa.o apps/genpkey.o apps/genrsa.o apps/nseq.o apps/ocsp.o apps/openssl.o apps/passwd.o apps/pkcs12.o apps/pkcs7.o apps/pkcs8.o apps/pkey.o apps/pkeyparam.o apps/pkeyutl.o apps/prime.o apps/rand.o apps/rehash.o apps/req.o apps/rsa.o apps/rsautl.o apps/s_client.o apps/s_server.o apps/s_time.o apps/sess_id.o apps/smime.o apps/speed.o apps/spkac.o apps/srp.o apps/storeutl.o apps/ts.o apps/verify.o apps/version.o apps/x509.o \
         apps/libapps.a -lssl -lcrypto -lz 
/home/mikro/gnu-tools-elf/m68000/lib/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: /home/mikro/gnu-tools-elf/m68000/m68k-atari-mintelf/sys-root/usr/lib/m68020-60/libc.a(syslog.o):(.bss+0x0): multiple definition of `_errno'; /home/mikro/gnu-tools-elf/m68000/m68k-atari-mintelf/sys-root/usr/lib/m68020-60/libc.a(errno.o):(.bss+0x0): first defined here
/home/mikro/gnu-tools-elf/m68000/lib/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: warning: sethostname.o: missing .note.GNU-stack section implies executable stack
/home/mikro/gnu-tools-elf/m68000/lib/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:6299: apps/openssl] Error 1
make[1]: Leaving directory '/home/mikro/atari/projects/_deps/openssl/openssl-1.1.1p'

Without having this fixed I can't confirm whether std::atomic works on software compiled by gcc-13-mintelf.

th-otto commented 1 year ago

The first is a bug in mintlib: https://github.com/freemint/mintlib/blob/209bf476deb670e83afa6c381bbba3287d35c028/misc/syslog.c#L88

This gives link errors with newer toolchains that default to -fno-common. Just pushed a fix for it.

The other is just an annoying warning from the linker. Not relevant for us, but i have to find a simple & clean solution to get rid of it.

mikrosk commented 1 year ago

Thanks Thorsten, I will try again tonight.

vinriviere commented 1 year ago

The first is a bug in mintlib: https://github.com/freemint/mintlib/blob/209bf476deb670e83afa6c381bbba3287d35c028/misc/syslog.c#L88

This gives link errors with newer toolchains that default to -fno-common. Just pushed a fix for it.

Thanks Thorsten for that fix for errno in syslog: https://github.com/freemint/mintlib/commit/e1d9a2a11ef3f3dbc645f79723cc88e704f9292e

I also hit that MiNTLib bug, but to avoid revealing my work on the mintelf toolchain, I cowardly added a workaround in my MiNTLib build script:

sed -i 's/^int errno/extern int errno/' misc/syslog.c

Of course your fix with errno.h is better.

vinriviere commented 1 year ago

For information, compilation of gdb requires the function __atomic_compare_exchange_1() which was undefined. By looking at the current atomic patches, it's not obvious if that issue is now fixed. I haven't tried yet. Maybe that's a completely different issue.

th-otto commented 1 year ago

I'll try to figure out where that reference comes from. I think the atomic function should all be available now.

Apropos gdb, any idea what the best environment would be? Natively, or using the gdb-server? Running gdb natively (or under some emulation) will be rather slow i think, especially when single-stepping. And since gdb will definitely require mint, this will probably mean aranym. I haven't used gdb-server yet, so i don't know whether that will be better.

th-otto commented 1 year ago

I think the atomic function should all be available now.

Or maybe not. The libgcc/config/m68k/mint-atomic.c file (and its reference in libgcc/config/m68k/t-mint) is missing in your patch.

mikrosk commented 1 year ago

Or maybe not. The libgcc/config/m68k/mint-atomic.c file (and its reference in libgcc/config/m68k/t-mint) is missing in your patch.

In his patch yes but it has been already rectified, i.e. your atomic patches are already part of the tree (plus I have force-pushed the clean version of it).

mikrosk commented 1 year ago

Verified as working, closing. That __atomic_compare_exchange_1 should be a separate issue.