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

Building for the x32 ABI #684

Open
svenha opened this issue Feb 28, 2023 · 5 comments
Open

Building for the x32 ABI #684

svenha opened this issue Feb 28, 2023 · 5 comments

Comments

@svenha
Copy link

svenha commented Feb 28, 2023

Hello.

I was able to build the scheme binary for the x32 ABI. I am interested in the x32 ABI because it can give significant speedups for GC-intensive programs and reduce memory usage by 50 % (observed for other Schemes like bigloo).

The following error during make shows that there seems to be some asserts or assumptions that differ for x32 compared to x86-64. Can I just modify them? If so, where and how?

make all
echo '(reset-handler abort)'\
            '(base-exception-handler (lambda (c) (fresh-line) (display-condition c) (newline) (reset)))'\
            '(keyboard-interrupt-handler (lambda () (display "interrupted---aborting\n") (reset)))'\
            '(optimize-level 3)'\
            '(debug-level 0)'\
            '(commonization-level (commonization-level))'\
            '(fasl-compressed #t)'\
            '(compress-format (compress-format))'\
            '(compress-level (compress-level))'\
            '(generate-inspector-information #f)'\
            '(subset-mode (quote system))'\
            '(compile-file "cmacros.ss" "cmacros.so")'\
            | ../bin/a6le/scheme -q
sizeof(ptr) * 8 [4] != ptr_bits [64]
sizeof(long) * 8 [4] != long_bits [64]
sizeof(size_t) * 8 [4] != size_t_bits [64]
sizeof(ssize_t) * 8 [4] != size_t_bits [64]
sizeof(ptrdiff_t) * 8 [4] != ptrdiff_t_bits [64]
sizeof(bigitbigit) [4] != sizeof(bigit) [4] * 2
sizeof(I64) [4] != 8
sizeof(U64) [4] != 8
make[4]: *** [Mf-base:372: cmacros.so] Error 1
make[3]: *** [Mf-base:176: allx] Error 2
make[2]: *** [Mf-base:193: bootstrap] Error 2
make[1]: *** [Makefile:22: build] Error 2
make: *** [Makefile:20: build] Error 2

I built the x32 binary by modifying the build process as follows (one needs x32 versions of ncurses, libuuid, libz, liblz4):

./configure ZLIB=/usr/local/libx32/libz.a LZ4=/usr/local/libx32/liblz4.a --machine=a6le --installbin=/usr/local/binx32 --installlib=/usr/local/libx32 --installman=/usr/local/share/man
 sed -i.orig -e '/s/ -m64/ -mx32/g' -e '/ -Werror/ / g' 's/elf_x86_64/elf32_x86_64/g' c/Mf-a6le
@burgerrg
Copy link
Contributor

Please use the i3le target, which is a 32-bit Intel architecture on Linux.

@svenha
Copy link
Author

svenha commented Feb 28, 2023

x32 ABI is not i386, but more like x86-64 with 32bit pointers, see https://en.wikipedia.org/wiki/X32_ABI for details.
You get the benefits of x86-64 (more registers, more instructions) without the memory overhead. The downside: your process cannot use more than 4 GB.

@melted
Copy link
Contributor

melted commented Mar 1, 2023

You could try modifying address-bits and ptr-bits in s/a6le.def and s/ta6le.def and see what happens.

@svenha
Copy link
Author

svenha commented Mar 1, 2023

@melted Thanks for the suggestions. I also changed ptrdiff_t-bits and size_t-bits (from 64 to 32), but the error message is the same.

@svenha
Copy link
Author

svenha commented Feb 27, 2024

I returned to the issue with a current git version.

Good news is that I ended up with a usable pb/scheme, which is an X32 binary:

pb/bin/pb/scheme: ELF 32-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /libx32/ld-linux-x32.so.2, BuildID[sha1]=2b0a68bb0e47dbfb0e2b6b45f7619eee514bbb38, for GNU/Linux 3.4.0, not stripped

The make step ends now as follows:

running pb/bin/pb/scheme to build all at once
loading ta6le cross compiler
compiling s/library.ss with output to xc-ta6le/s/library.ta6le
Exception in assembler-internal: ax-ea-imm-data size=quad imm-data=(literal 33 (library #(libspec nonprocedure-code 160)))
failed
in build-one
in loop
in module->hash
make: *** [Makefile:10: build] Error 1

For context, this is how I build chez-scheme:

CC=gccx32 ./configure --installprefix=/usr/local # gccx32 is script specifying gcc -mx32
sed -i.orig -e 's/-m64 /-mx32 /g' -e 's/ -Werror/ / g' -e 's/elf_x86_64/elf32_x86_64/g' ta6le/Mf-config
sed -i.orig -e 's/ptr-bits 64/ptr-bits 32/g' s/a6.def
sed -i.orig -e 's/ long-bits .*/ long-bits 64)/g' s/default.def
make

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

3 participants