Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `__sync_bool_compare_and_swap_4' #37

Open
stsp opened this issue Aug 27, 2023 · 10 comments
Open

undefined reference to `__sync_bool_compare_and_swap_4' #37

stsp opened this issue Aug 27, 2023 · 10 comments

Comments

@stsp
Copy link

stsp commented Aug 27, 2023

Using __sync intrinsics by default
results into an error.
Changing -march solves the problem,
but things should work by default.

@jwt27
Copy link
Owner

jwt27 commented Aug 27, 2023

386 doesn't have cmpxchg, you'll need -march=i486 at minimum. I do want the debian/ubuntu packages to produce 386 code by default, so won't fix.

@stsp
Copy link
Author

stsp commented Aug 27, 2023

Undefined reference is not an answer.
If you want to support i386, then you need
to update libgcc to include the replacements.

@jwt27
Copy link
Owner

jwt27 commented Aug 27, 2023

I think those are in libatomic. Have you considered other solutions? For atomic flags you generally only need __atomic_test_and_set() (which is just regular xchg).

@stsp
Copy link
Author

stsp commented Aug 27, 2023

Have you considered other solutions?

Tried just now:
undefined reference to `__atomic_fetch_sub_4'

generally only need __atomic_test_and_set() (which is just regular xchg).

How so?

@stsp
Copy link
Author

stsp commented Aug 27, 2023

I think those are in libatomic

Its probably unavailable in your build.
-latomic doesn't seem to work.

@stsp
Copy link
Author

stsp commented Aug 27, 2023

386 doesn't have cmpxchg, you'll need -march=i486 at minimum. I do want the
debian/ubuntu packages to produce 386 code by default, so won't fix.

How far does 486 go besides atomics?
If atomics is the only extension, then, as
they are probably not emitted by the
compiler on his own (unless the user
explicitly used the intrinsic), you are
safe?
I know gcc can emit cmov, but that one
is far ahead of i486. So why i486 by
default is unsafe?

@jwt27
Copy link
Owner

jwt27 commented Aug 27, 2023

I think those are in libatomic

Its probably unavailable in your build. -latomic doesn't seem to work.

It hasn't been ported to djgpp yet, I guess no one ever needed it.

386 doesn't have cmpxchg, you'll need -march=i486 at minimum. I do want the
debian/ubuntu packages to produce 386 code by default, so won't fix.

How far does 486 go besides atomics? If atomics is the only extension, then, as they are probably not emitted by the compiler on his own (unless the user explicitly used the intrinsic), you are safe? I know gcc can emit cmov, but that one is far ahead of i486. So why i486 by default is unsafe?

bswap is 486+, and that is fairly common.

@stsp
Copy link
Author

stsp commented Aug 27, 2023

Maybe if you use -mtune=i386
then it won't use anything of 486
unless explicitly asked?
Just a guess.

@jwt27
Copy link
Owner

jwt27 commented Aug 27, 2023

Maybe if you use -mtune=i386 then it won't use anything of 486 unless explicitly asked? Just a guess.

-mtune only affects instruction timings, so that doesn't help:

$ cat test.c
unsigned test(unsigned x)
{
  return (x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24);
}

$ i386-pc-msdosdjgpp-gcc -S -O3 -masm=intel -march=i486 -mtune=i386 test.c -o -
        .file   "test.c"
        .intel_syntax noprefix
        .section .text
        .p2align 2
        .globl  _test
_test:
        push    ebp
        mov     ebp, esp
        mov     eax, DWORD PTR [ebp+8]
        bswap   eax
        pop     ebp
        ret
        .ident  "GCC: (GNU) 12.2.0"

@stsp
Copy link
Author

stsp commented Aug 27, 2023

I was hoping it to deduce that the
timing of bswap on 386 is veeery
poor. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants