Gas64 (no more use of gcc, only gas) WDS / LNX

User projects written in or related to FreeBASIC.
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 24, 2020 0:39

@xusinboy
Sorry It was a stupid request but I saw that afterwards.
It's just the address of ondraw function.... What I wanted was the returned value.

Anyway maybe I found the problem : as the returned value by ondraw is 0 (any doubt) I only see a problem of size as boolean in gtk is int and boolean in fbc byte.
It's possible that the register (rax) used for returning the value contains already something and as only a byte is moved inside it the value of size int could be not null.

Test with this version of ir-gas where the register is zeroed before moving the boolean inside. http://users.freebasic-portal.de/sarg/ir-gas64.zip

@robert
There is something not well synchronized (compilation with gcc/gas64, version of fbc's sources). The missing links are for functions added in january.
To understand I'll try to reproduce these errors on my side.
Xusinboy Bekchanov
Posts: 156
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby Xusinboy Bekchanov » Mar 24, 2020 17:44

SARG wrote:@xusinboy
Sorry It was a stupid request but I saw that afterwards.
It's just the address of ondraw function.... What I wanted was the returned value.

Anyway maybe I found the problem : as the returned value by ondraw is 0 (any doubt) I only see a problem of size as boolean in gtk is int and boolean in fbc byte.
It's possible that the register (rax) used for returning the value contains already something and as only a byte is moved inside it the value of size int could be not null.

Test with this version of ir-gas where the register is zeroed before moving the boolean inside. http://users.freebasic-portal.de/sarg/ir-gas64.zip

Thanks, it works.
Now, when compiling the library, it returns this error:

Code: Select all

22:37:47: Compilation: "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/fbc64_gas64"  -b "mff.bi" -x "../libmff32_gtk3.so" -dll -exx -s gui -g -i "/media/GitHub/VisualFBEditor/MyFbFramework" ...

ld: mff.o: relocation R_X86_64_PC32 against символ `fb_ErrorSetModName' can not be used when making общий объект; перекомпилируйте с параметром -fPIC
ld: final link failed: Некорректное значение

22:38:16: Do not build file.

I mailed you the source.
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 24, 2020 20:09

Xusinboy Bekchanov wrote:Thanks, it works.
Fine. Fortunately because I had no other idea. :-)

About the error.
ld: mff.o: relocation R_X86_64_PC32 against the symbol `fb_ErrorSetModName 'can not be used when making a shared object; recompile with the -fPIC option
Add '-no-pie' for the linker (-Wl -no-pie).
What I found : for security reason dlls, by default, are position independent (pie). Maybe gcc adds the option no-pie or -fPIC by default but obviously not done when fbc64_gas64 is used. Check with -v if you can see that in the log.

Edit : confirmed there is the option -fPIC when compiling for creating a dll under Linux.
Xusinboy Bekchanov
Posts: 156
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby Xusinboy Bekchanov » Mar 25, 2020 1:56

SARG wrote:About the error.
ld: mff.o: relocation R_X86_64_PC32 against the symbol `fb_ErrorSetModName 'can not be used when making a shared object; recompile with the -fPIC option
Add '-no-pie' for the linker (-Wl -no-pie).
What I found : for security reason dlls, by default, are position independent (pie). Maybe gcc adds the option no-pie or -fPIC by default but obviously not done when fbc64_gas64 is used. Check with -v if you can see that in the log.

Edit : confirmed there is the option -fPIC when compiling for creating a dll under Linux.

No, it didn't help, it repeats the same mistake. I tried to do separately and with -no-pie and with -fPIC and together these keys. Here:

Code: Select all

07:01:24: Compilation: "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/fbc64_gas64"  -b "mff.bi" -x "../libmff64_gtk3.so" -dll -v -exx -Wl -fPIC -Wl -no-pie -g -i "/media/GitHub/VisualFBEditor/MyFbFramework" ...

FreeBASIC Compiler - Version 1.07-(08).0 (2020-03-21), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
target:       linux-x86_64, x86-64, 64bit
backend:      gas64
compiling:    mff.bi -o mff.a64 (main module)
assembling:   as --64 "mff.a64" -o "mff.o"
linking:      ld -m elf_x86_64 -o "../libmff64_gtk3.so" -shared -hlibmff64_gtk3.so --export-dynamic "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbextra.x" -L "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64" -L "." -L "/usr/lib/gcc/x86_64-linux-gnu/7" "/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o" "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbrt0pic.o" "mff.o" "-(" -lgtk-3 -lgdk-3 -lglib-2.0 -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lpangocairo-1.0 -latk-1.0 -lfbpic -ltinfo -lm -ldl -lpthread -lgcc -lgcc_eh -lc "-)" "/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o" "/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o"  -fPIC  -no-pie
linking failed: 'ld' terminated with exit code 1
ld: mff.o: relocation R_X86_64_PC32 against символ `fb_ErrorSetModName' can not be used when making общий объект; перекомпилируйте с параметром -fPIC
ld: final link failed: Некорректное значение

07:01:54: Do not build file.

Here the -fPIC switch is passed to compile the C code:

Code: Select all

07:16:13: Compilation: "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/fbc"  -b "mff.bi" -x "../libmff64_gtk3.so" -dll -v -exx -g -i "/media/GitHub/VisualFBEditor/MyFbFramework" ...

FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
target:       linux-x86_64, x86-64, 64bit
compiling:    mff.bi -o mff.c (main module)
compiling C:  gcc -m64 -march=x86-64 -fPIC -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format -g -masm=intel "mff.c" -o "mff.asm"
assembling:   as --64 "mff.asm" -o "mff.o"
linking:      ld -m elf_x86_64 -o "../libmff64_gtk3.so" -shared -hlibmff64_gtk3.so --export-dynamic "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbextra.x" -L "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64" -L "." -L "/usr/lib/gcc/x86_64-linux-gnu/7" "/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o" "/media/FreeBasic/FreeBASIC-1.07.1-linux-x86_64/bin/../lib/freebasic/linux-x86_64/fbrt0pic.o" "mff.o" "-(" -lgtk-3 -lgdk-3 -lglib-2.0 -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lpangocairo-1.0 -latk-1.0 -lfbpic -ltinfo -lm -ldl -lpthread -lgcc -lgcc_eh -lc "-)" "/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o" "/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o"

07:17:23: Layout succeeded!
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 25, 2020 10:33

Hi all and especially my favorite testers :-)

@robert
The rtlib must also be updated for 1.08. You can get it from St_W's daily build, files are in lib folder.
http://users.freebasic-portal.de/stw/bu ... -01-12.zip
I hope it solves the problem.

@xusinboy
Fb_errorsetmodname is a function in error_getset.c, an rtlib file. Shared libraries, under Linux, must be compiled with the option -fPIC : position independant code. I'm learning every day.

Did you also compile rtlib with gas64 ?
If it's the case it could explain the problem. For now I study how fPIC and FPIE are working to eventually do changes in ir-gas64.
Xusinboy Bekchanov
Posts: 156
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby Xusinboy Bekchanov » Mar 25, 2020 15:11

SARG wrote:Did you also compile rtlib with gas64 ?

No, I did not compile
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 25, 2020 20:23

@xusinboy
Thanks to the files you sent me I understand better what is happening and what I have to do.

This short code to explain the problem.

Code: Select all

sub foo
end sub
dim as psub = @foo
When compiling as dll you get the error about relocation.
The generated code for psub=@foo is position independent but doesn't go in a mandatory table for dll when linking.

Code: Select all

lea rax, foo[rip]
must be replaced by

Code: Select all

mov rax,QWORD PTR foo@GOTPCREL[rip]
Therefore I just have a bit of work for fbc64 being compliant with dlls under Linux. New version tomorrow.

@dodicat
I do test out code on SARG's GAS64, but my knowledge of assembler is not good enough to make sensible contributions.
But GAS64 it is a brilliant project to escape gcc.
I read that with a great pleasure. Thanks.
Tests and reports are a strong help. Assembler issues can stay on my side but all advices are welcome.
robert
Posts: 60
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby robert » Mar 25, 2020 21:09

[quote="SARG"]Hi all and especially my favorite testers :-)

@robert
The rtlib must also be updated for 1.08. You can get it from St_W's daily build, files are in lib folder.
http://users.freebasic-portal.de/stw/bu ... -01-12.zip
I hope it solves the problem.
/quote]

No, it's even worse. You don't want to go there.
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 25, 2020 21:32

Worse, What do you get ?
robert
Posts: 60
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby robert » Mar 25, 2020 21:39

robert wrote:
SARG wrote:Hi all and especially my favorite testers :-)

@robert
The rtlib must also be updated for 1.08. You can get it from St_W's daily build, files are in lib folder.
http://users.freebasic-portal.de/stw/bu ... -01-12.zip
I hope it solves the problem.
/quote]

No, it's even worse. You don't want to go there.


Just to clarify, here is my setup

On Fedora 31 x64

1. I download and install the daily 1.0.8 daily build from St_W.

2. I git the latest source from the FreeBASIC Github repository and compile and install it. The compilation/installation must be done three times.

3. I, again, git the latest source from the FreeBASIC Github repository and install it to a fbcGAS directory.

4. I download your latest fbc64_gas64.zip and unpack it and copy the 9 files from the sources directory to the fbcGAS/src/compiler/ directory.

5 I then run make from fbcGAS root directory and then make install. The gas64 backend fbc is now the default fbc compiler. This is done three times.

Back to your suggestion of copying the the rtlib.o from the standard install. This abominable kludge was done and was a disaster. The make unit-tests failed immediately.

Then FreeBASIC was completely uninstalled and a fresh install of the the daily 1.0.8 daily build from St_W was done.

A copy of fbc64_gas64 was put in place of the stock fbc and make unit-tests was run again with the same immediate failure.

What to do ? Who knows ?
robert
Posts: 60
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby robert » Mar 25, 2020 21:52

SARG wrote:Worse, What do you get ?


I will let you know shortly. I'm doing another cleanup and reinstall.
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 25, 2020 22:46

@robert
The important point is to get these files from daily build (for the lib folder) :
fbextra.x
fbrt0.o
fbrt0pic.o
libfb.a
libfbgfx.a
libfbgfxmt.a
libfbgfxmtpic.a
libfbgfxpic.a
libfbmt.a
libfbmtpic.a
libfbpic.a
They are ok for version 1.08.
Don't do anything with rtlib.o. It was not a clear suggestion, only the files above.
Take the latest source version 1.08. Change by my provided files. It should be good.
I'll try on my Linux box. Maybe I'll find what is wrong.
I'm tenacious therefore we are going to find the right method.
robert
Posts: 60
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby robert » Mar 25, 2020 23:31

SARG wrote:@robert
The important point is to get these files from daily build (for the lib folder) :
fbextra.x
fbrt0.o
fbrt0pic.o
libfb.a
libfbgfx.a
libfbgfxmt.a
libfbgfxmtpic.a
libfbgfxpic.a
libfbmt.a
libfbmtpic.a
libfbpic.a
They are ok for version 1.08.
Don't do anything with rtlib.o. It was not a clear suggestion, only the files above.
Take the latest source version 1.08. Change by my provided files. It should be good.
I'll try on my Linux box. Maybe I'll find what is wrong.
I'm tenacious therefore we are going to find the right method.


O.K. We shall let the past be the past.

I have moved the files contained in fbc_linux64_0578_2020-01-12.zip

Code: Select all

2020-01-12 18:33:26.000000000 -0800 396 fbextra.x
2020-01-12 18:33:26.000000000 -0800 1792 fbrt0.o
2020-01-12 18:35:10.000000000 -0800 1840 fbrt0pic.o
2020-01-12 18:35:10.000000000 -0800 991316 libfb.a
2020-01-12 18:39:38.000000000 -0800 305216 libfbgfx.a
2020-01-12 18:40:12.000000000 -0800 315088 libfbgfxmt.a
2020-01-12 18:40:30.000000000 -0800 303080 libfbgfxmtpic.a
2020-01-12 18:39:56.000000000 -0800 293352 libfbgfxpic.a
2020-01-12 18:37:58.000000000 -0800 1021502 libfbmt.a
2020-01-12 18:39:20.000000000 -0800 1051286 libfbmtpic.a
2020-01-12 18:36:34.000000000 -0800 1020932 libfbpic.a

to /usr/local/lib/freebasic/linux-x86_64/

and when running make unit-tests with your gas64 backend fbc, the output

Code: Select all

fbc -l fbcunit -p fbcunit/lib -x fbc-tests @unit-tests-obj.lst ./fbc-tests.o
./pretest/style_simple.o() warning 20(3): Object files or libraries with mixed multithreading (-mt) options
ld: ./fbc-int/array.o: in function `TESTS::FBC_TESTS::FBC_INT::ARRAY::STATIC_FIXED()':
(.text+0x13): undefined reference to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)'
ld: (.text+0x34d): undefined reference to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)'
ld: ./fbc-int/array.o: in function `TESTS::FBC_TESTS::FBC_INT::ARRAY::STATIC_EMPTY()':
(.text+0x78e): undefined reference to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)'
ld: (.text+0xf6d): undefined reference to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)'
ld: (.text+0x17fe): undefined reference to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)'
ld: ./fbc-int/array.o:(.text+0x24b0): more undefined references to `FBC::fb_ArrayGetDesc(FBARRAY<void>&)' follow
ld: ./fbc-int/memory.o: in function `TESTS::FBC_TESTS::FBC_INT::MEMORY::CLEAR_()':
(.text+0x16): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x29): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x1af): undefined reference to `FBC::memset(void*, int, unsigned long)'
ld: (.text+0x285): undefined reference to `FBC::free(void const*)'
ld: (.text+0x28e): undefined reference to `FBC::free(void const*)'
ld: ./fbc-int/memory.o: in function `TESTS::FBC_TESTS::FBC_INT::MEMORY::ALLOCS()':
(.text+0x2ad): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x2bb): undefined reference to `FBC::malloc(unsigned long)'
ld: (.text+0x2cb): undefined reference to `FBC::realloc(void const*, unsigned long)'
ld: (.text+0x2e1): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x314): undefined reference to `FBC::memcpy(void*, void const*, unsigned long)'
ld: (.text+0x329): undefined reference to `FBC::memmove(void*, void const*, unsigned long)'
ld: (.text+0x480): undefined reference to `FBC::memset(void*, int, unsigned long)'
ld: (.text+0x490): undefined reference to `FBC::memset(void*, int, unsigned long)'
ld: (.text+0x4a3): undefined reference to `FBC::memset(void*, int, unsigned long)'
ld: (.text+0x6a1): undefined reference to `FBC::free(void const*)'
ld: (.text+0x6ad): undefined reference to `FBC::free(void const*)'
ld: (.text+0x6b6): undefined reference to `FBC::free(void const*)'
ld: (.text+0x6bf): undefined reference to `FBC::free(void const*)'
ld: ./fbc-int/memory.o: in function `TESTS::FBC_TESTS::FBC_INT::MEMORY::MEMMOVE_()':
(.text+0x6de): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x6f1): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x770): undefined reference to `FBC::memmove(void*, void const*, unsigned long)'
ld: (.text+0x8cd): undefined reference to `FBC::memmove(void*, void const*, unsigned long)'
ld: (.text+0x9b1): undefined reference to `FBC::free(void const*)'
ld: (.text+0x9ba): undefined reference to `FBC::free(void const*)'
ld: ./fbc-int/memory.o: in function `TESTS::FBC_TESTS::FBC_INT::MEMORY::USING_FBC()':
(.text+0x9d9): undefined reference to `_ZN3FBC6callocEmS0_'
ld: (.text+0x9f7): undefined reference to `FBC::realloc(void const*, unsigned long)'
ld: (.text+0xa0d): undefined reference to `_ZN3FBC6callocEmS0_'
ld: ./fbc-int/memory.o: in function `ALLOCATE':
(.text+0xa8e): undefined reference to `FBC::malloc(unsigned long)'
ld: ./fbc-int/memory.o: in function `DEALLOCATE':
(.text+0xaba): undefined reference to `FBC::free(void const*)'
make[1]: *** [unit-tests.mk:178: build_tests] Error 1
make[1]: Leaving directory '/home/rwishlaw/Dev/fbcGAS/tests'
make: *** [Makefile:158: unit-tests] Error 2


is still the same error.
robert
Posts: 60
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby robert » Mar 25, 2020 23:53

Standard install of St. W's daily build.

The only change was that fbc was replaced with Fedora 31 make compiled fbc64_gas64.

Running make unit-tests errored with

Code: Select all

make unit-tests
make -f unit-tests.mk
make[1]: Entering directory '/home/rwishlaw/Dev/fbcGAS/tests'
Generating unit-tests.inc : Done
cd fbcunit && make FPU= ARCH= TARGET=
make[2]: Entering directory '/home/rwishlaw/Dev/fbcGAS/tests/fbcunit'
fbc -mt -g -exx -i ./inc -lib src/fbcunit.bas src/fbcunit_qb.bas src/fbcunit_console.bas src/fbcunit_report.bas -x lib/libfbcunit.a
src/fbcunit_console.bas(8) error 23: File not found, "crt/stdio.bi" in '#include once "crt/stdio.bi"'
make[2]: *** [makefile:91: lib/libfbcunit.a] Error 1
make[2]: Leaving directory '/home/rwishlaw/Dev/fbcGAS/tests/fbcunit'
make[1]: *** [unit-tests.mk:145: fbcunit/lib/libfbcunit.a] Error 2
make[1]: Leaving directory '/home/rwishlaw/Dev/fbcGAS/tests'
make: *** [Makefile:158: unit-tests] Error 2


Similar problem. Can't find includes.
SARG
Posts: 1000
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 26, 2020 11:30

@robert
Let's try otherwise.
- install a fresh current release 1.07(1)
- run the test suite (1.07 version) with gcc
- If all is right (it should be) run again the test suite after replacing regular fbc by fbc64_gas compiled with version 1.07 (the 9 files are compatible 1.07/1.08).
If all is still ok we'll go to the next step.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests