02 March 2021, 21:32 | #1 |
Registered User
Join Date: Jun 2016
Location: UK
Posts: 428
|
Assembler files and C in GCC / bartman's amiga-debug
I'm using bartman's amiga-debug VScode extension and I want to include some assembler files in my project.
I tried to modify the makefile like this: Code:
s_sources := $(wildcard *.s) $(wildcard $(addsuffix *.s,$(subdirs))) s_objects := $(addprefix obj/,$(patsubst %.s,%.o,$(notdir $(s_sources)))) objects := $(cpp_objects) $(c_objects) $(s_objects) Code:
$(s_objects): obj/%.o : %.s $(info Assembling $<) @$(CC) $(CCFLAGS) $(ASFLAGS) -xassembler-with-cpp -c -o $@ $(CURDIR)/$< Code:
Compiling main.c Compiling support/gcc8_c_support.c Assembling vfill.s Assembling support/gcc8_a_support.s Linking a.mingw.elf c:/users/zero/.vscode/extensions/bartmanabyss.amiga-debug-1.0.0/bin/opt/bin/../lib/gcc/m68k-amiga-elf/10.1.0/../../../../m68k-amiga-elf/bin/ld.exe: obj/gcc8_a_support.o: in function `__mulsi3': D:/Amiga/code/test1/support/gcc8_a_support.s:40: multiple definition of `__mulsi3'; obj/gcc8_a_support.o:D:/Amiga/code/test1/support/gcc8_a_support.s:40: first defined here c:/users/zero/.vscode/extensions/bartmanabyss.amiga-debug-1.0.0/bin/opt/bin/../lib/gcc/m68k-amiga-elf/10.1.0/../../../../m68k-amiga-elf/bin/ld.exe: obj/gcc8_a_support.o: in function `__udivsi3': D:/Amiga/code/test1/support/gcc8_a_support.s:59: multiple definition of `__udivsi3'; obj/gcc8_a_support.o:D:/Amiga/code/test1/support/gcc8_a_support.s:59: first defined here c:/users/zero/.vscode/extensions/bartmanabyss.amiga-debug-1.0.0/bin/opt/bin/../lib/gcc/m68k-amiga-elf/10.1.0/../../../../m68k-amiga-elf/bin/ld.exe: obj/gcc8_a_support.o: in function `__divsi3': D:/Amiga/code/test1/support/gcc8_a_support.s:112: multiple definition of `__divsi3'; obj/gcc8_a_support.o:D:/Amiga/code/test1/support/gcc8_a_support.s:112: first defined here c:/users/zero/.vscode/extensions/bartmanabyss.amiga-debug-1.0.0/bin/opt/bin/../lib/gcc/m68k-amiga-elf/10.1.0/../../../../m68k-amiga-elf/bin/ld.exe: obj/gcc8_a_support.o: in function `__modsi3': ... |
03 March 2021, 00:37 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
It can't decide to cross compile to the Amiga or compile with Windows native linker files, it looks like to me.
|
03 March 2021, 08:13 | #3 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Have you definitely done a clean after modifying your makefile? There aren't any left over .o files anywhere?
When I wanted to add assembly files to my project I found that the gcc assembler was just not useable. I used vasm instead and named the files I wanted it to assemble with a different suffix so that I could create a separate process within the makefile for them. Then you're free to do what you want without breaking any existing stuff. Edit: I see you need -xassembler-with-cpp. My solution won't work for you if this is the case, unless you can break that into a separate step. Edit 2: How do you stop it from trying to assemble the generated a.mingw.s file? Also, are you on the latest preview version of the vscode extension? Edit 3: This works for me, apart from that pesky a.mingw.s, using the latest preview extension. I've added a test.s file with one test function included. Not an exhaustive test, but no errors. I would still recommend adding in vasm instead though. Code:
# to generate assembler listing with LTO, add to LDFLAGS: -Wa,-adhln=$@.listing,--listing-rhs-width=200 # for better annotations add -dA -dP # to generate assembler source with LTO, add to LDFLAGS: -save-temps=cwd forward-to-backward = $(subst /,\,$1) subdirs := $(wildcard */) VPATH = $(subdirs) cpp_sources := $(wildcard *.cpp) $(wildcard $(addsuffix *.cpp,$(subdirs))) cpp_objects := $(addprefix obj/,$(patsubst %.cpp,%.o,$(notdir $(cpp_sources)))) c_sources := $(wildcard *.c) $(wildcard $(addsuffix *.c,$(subdirs))) c_objects := $(addprefix obj/,$(patsubst %.c,%.o,$(notdir $(c_sources)))) s_sources := $(wildcard *.s) $(wildcard $(addsuffix *.s,$(subdirs))) s_objects := $(addprefix obj/,$(patsubst %.s,%.o,$(notdir $(s_sources)))) objects := $(cpp_objects) $(c_objects) $(s_objects) # https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile/4038459 # http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html OUT = a.mingw CC = m68k-amiga-elf-gcc CCFLAGS = -g -MP -MMD -m68000 -Ofast -nostdlib -Wextra -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions ASFLAGS = -Wa,-g,--register-prefix-optional LDFLAGS = -Wl,--emit-relocs,-Ttext=0,-Map=$(OUT).map all: $(OUT).exe $(OUT).exe: $(OUT).elf $(info Elf2Hunk $(OUT).exe) @elf2hunk $(OUT).elf $(OUT).exe $(OUT).elf: $(objects) $(info Linking a.mingw.elf) @$(CC) $(CCFLAGS) $(LDFLAGS) $(objects) -o $@ @m68k-amiga-elf-objdump --disassemble --no-show-raw-ins --visualize-jumps -S $@ >$(OUT).s clean: $(info Cleaning...) @del /q obj $(OUT).* 2>nul || rmdir obj 2>nul || ver>nul -include $(objects:.o=.d) $(cpp_objects) : obj/%.o : %.cpp @if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@)) $(info Compiling $<) @$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$< $(c_objects) : obj/%.o : %.c @if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@)) $(info Compiling $<) @$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$< $(s_objects): obj/%.o : %.s $(info Assembling $<) @$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$< Last edited by Ernst Blofeld; 03 March 2021 at 10:12. |
03 March 2021, 20:37 | #4 |
Registered User
Join Date: Jun 2016
Location: UK
Posts: 428
|
Thanks Ernst, that fixed it!
I hate makefiles, not because they are terrible but because I only do them occasionally and always forget how to debug them in-between. |
12 March 2021, 05:07 | #5 |
Registered User
Join Date: Jun 2020
Location: Druidia
Posts: 389
|
I wanted to do the same thing and compile any .s file I added to the project. I don't really know how all the makefile voodoo works but was able to come up with this solution that avoids renaming the output .s file.
s_sources := $(subst $(OUT).s,,$(wildcard *.s) $(wildcard $(addsuffix *.s,$(subdirs)))) You also need to move OUT up before this line. |
12 March 2021, 08:25 | #6 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
|
|
12 March 2021, 13:41 | #7 |
Registered User
Join Date: Jun 2020
Location: Druidia
Posts: 389
|
Not good! I wasn’t expecting it to be so different.
Not sure if it’s worth pushing on with or getting vasm going. What’s been you experience with that? |
12 March 2021, 13:57 | #8 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
vasm has been totally faultless. -Felf to make it fall in line with the rest of the build process and it just works.
|
12 March 2021, 14:52 | #9 |
Registered User
Join Date: Jun 2016
Location: UK
Posts: 428
|
I haven't used vasm, and only done a tiny bit of 68k in the GNU assembler. I've done a lot of AVR asm in the GNU assembler though and it's been fine... What is the advantage of vasm?
|
12 March 2021, 15:02 | #10 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
For me, just that it supports the syntax that I still remember from the first time round. gas supports a different standard. It can be somewhat flexible about it, and it's your only choice for inline stuff, but it's not the same experience.
|
12 March 2021, 15:36 | #11 |
Registered User
Join Date: Jun 2020
Location: Druidia
Posts: 389
|
I've done lots of inline asm and that is relatively nice. You do have to learn the rules for specifying registers and clobbers and all that but it's manageable.
Where it breaks down for me is when your inline asm is pushing the limit of how many registers there are. It seems I can write code that uses them all and it'll compile fine sometimes but in a different context, maybe because other code changed, it'll fail. Mostly seems to be the optimizer running into trouble. So, I had a quick look at adding .s files and immediately ran into unfamiliar syntax, even compared to the inline stuff. Maybe it's worth learning all that, but on the other hand if I want to integrate code from other places for a mod player or whatever it'll all need ported to the new syntax. What's not clear to me is if there is a downside using vasm. We should probably ask Bartman on Github what he thinks. Btw. What is this: -x assembler-with-cpp option? I can't find any documentation for that anywhere. |
12 March 2021, 16:17 | #12 | |
Registered User
Join Date: Jun 2016
Location: UK
Posts: 428
|
Quote:
I am only just getting back into 68k assembler and never used it with C before, but on other platforms like AVR and ARM even with inline you have to observe some rules for register preservation. For example on AVR you must clear r1, the complied always expects it to be zero even if you said you clobbered it. I wish the inline syntax was a bit better, it's just annoying and awkward. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
GCC Assembler return value question... | NovaCoder | Coders. Asm / Hardware | 0 | 23 June 2012 07:11 |
where are header files located in GCC ? | Morbane | Coders. General | 0 | 05 January 2012 11:42 |
Linking to assembler objects using C++ gcc (StormV4) | NovaCoder | Coders. General | 6 | 09 December 2009 19:35 |
Assembler files in the zone | redblade | Coders. General | 0 | 06 September 2004 03:51 |
Do The Bartman | Djay | request.Demos | 4 | 27 May 2004 01:35 |
|
|