Assembly project without C

New to XMOS and XCore? Get started here.
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

Assembly project without C

Postby diltsman » Sun Mar 03, 2013 11:40 pm

I am playing around with programming in assembly and I have run in to a couple of issues. I hope that someone can help me figure out what I am missing.

I created an empty project for the XC-1A. I added a main.s file with a .globl main label in a .text section that does nothing. When I try to compile it I get "ERROR: Unable to open output file '../.build_Debug/src/main.s.o' for writing elf".

When I add a blank .c file everything compiles and links successfully.

If, at this point, I make the main label local (remove .globl) then I get "crt1.S: Error: Undefined reference to 'main'". I imagine that this is the C runtime failing to link due to a missing symbol.

So, my two questions. 1. How do I get a project to compile with just .s files? 2. How do I get the project to not use the C runtime?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Wed Mar 06, 2013 1:20 pm

diltsman wrote:I am playing around with programming in assembly and I have run in to a couple of issues. I hope that someone can help me figure out what I am missing.

I created an empty project for the XC-1A. I added a main.s file with a .globl main label in a .text section that does nothing. When I try to compile it I get "ERROR: Unable to open output file '../.build_Debug/src/main.s.o' for writing elf".
This appears to be a bug with the makefiles, I've filed a bug here:

https://github.com/xcore/xcommon/issues/15

This bug only affects lowercase .s files, not uppercase .S files. For now I suggest you rename you assembly files to use the .S extension. This also lets you use the C preprocessor (#includes, macros, C style comments).
diltsman wrote:If, at this point, I make the main label local (remove .globl) then I get "crt1.S: Error: Undefined reference to 'main'". I imagine that this is the C runtime failing to link due to a missing symbol.
This is correct. The following options can be used to control what you link against:

Code: Select all

-nodefaultlibs           Compile without system libraries
-nostartfiles            Compile without system startup files
-nostdlib                Compile without system libraries and startup files
To use these in the Makefile add these to the XCC_MAP_FLAGS variable.

One issue you might run into is that the order in which the object files are linked is unspecified, so if you have multiple input files the you won't know which code gets executed first. If you are calling xcc directly you can solve this by compiling this startup code into an object file and using:

Code: Select all

xcc -nostartfiles -Xmapper --first -Xmapper startup.o <other input files here>
I'm not sure if it is possible to do this with the standard Makefiles - you may end up having to write your own.
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

Postby diltsman » Wed Mar 06, 2013 7:41 pm

richard wrote:To use these in the Makefile add these to the XCC_MAP_FLAGS variable.
When I added the flags to XCC_MAP_FLAGS it didn't work. When I added them to XCC_MAP_FLAGS_Release and XCC_MAP_FLAGS_Debug it did. Is this expected behavior?
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Postby davelacey » Thu Mar 07, 2013 9:29 am

diltsman wrote:
richard wrote:To use these in the Makefile add these to the XCC_MAP_FLAGS variable.
When I added the flags to XCC_MAP_FLAGS it didn't work. When I added them to XCC_MAP_FLAGS_Release and XCC_MAP_FLAGS_Debug it did. Is this expected behavior?
That is expected behaviour. If you have XCC_FLAGS_Release and XCC_FLAGS_Debug then this defines two build configurations and all other flags (XCC_MAP_FLAGS, XCC_ASM_FLAGS etc) need to be set with the prefix relevant to the build config.

If you only want one build configuration you can omit the suffices on all the settings.

Dave

Who is online

Users browsing this forum: No registered users and 2 guests