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 'memset' on macOS/arm64 #4

Open
aaroneiche opened this issue Jul 1, 2024 · 8 comments
Open

undefined reference to 'memset' on macOS/arm64 #4

aaroneiche opened this issue Jul 1, 2024 · 8 comments

Comments

@aaroneiche
Copy link

aaroneiche commented Jul 1, 2024

I'm not sure if its worth reopening issue #1 or just starting a new one, I'm running into a similar build error trying to build on an M1 MBP running Ventura (macOS 13.6.7)

Darwin Aarons-MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Mon Apr 22 20:49:37 PDT 2024; root:xnu-8796.141.3.705.2~1/RELEASE_ARM64_T6000 arm64

aeiche@Aarons-MacBook-Pro tiny_tris % make all
Building tiny_tris.elf ...
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/v8/dwyhdmqn68bf9f2rm974l_lw0000gn/T//cch3OBog.ltrans0.ltrans.o: in function `main':
/Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:362:(.text.startup.main+0x46a): undefined reference to `memset'
collect2: error: ld returned 1 exit status
make: *** [tiny_tris.elf] Error 1

I added the following to the makefile to fix an environment compiling error:

ifeq ($(shell uname -m),arm64)
	LDFLAGS +=  -march=rv32imac -mabi=ilp32
endif

But otherwise the makefile is as it was.
I haven't been able to figure out a fix other than what's already addressed in issue #1. (and that's in the makefile already, obvious)

@aaroneiche
Copy link
Author

I managed to find an answer that seems to have at least gotten me through compiling.

https://forums.raspberrypi.com/viewtopic.php?t=84506:

Lowering the optimization flag to -O2 fixes the issue. Still wondering why the programmers assumed that 'memset' is available when other flags indicates that no system/default libraries are to use.

I put this in under my changes to LDFLAGS and the compiling completed without complaint.

	CFLAGS += -O2

I'll work on a PR.

@wagiminator
Copy link
Owner

Hi and thank you. This is really strange. I will make some tests when I find some time. There must be a better solution, I hope.

@aaroneiche
Copy link
Author

I'll note here additionally that the flag makes compiling work, but the code doesn't actually run. I'm not entirely sure why - I'll continue to explore.

@wagiminator
Copy link
Owner

I think that's because of the rv32imac flag. The ch32v003 doesn't actually support this instruction set.

@aaroneiche
Copy link
Author

Ahh yes, that makes sense. I'm compiling for the wrong thing. I am unfortunately back to unsuccessfully compiling on Apple Silicon/arm64.

aeiche@Aarons-MacBook-Pro tiny_tris % make all  
Building tiny_tris.elf ...
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/libgcc.a(div.o): ABI is incompatible with that of the selected emulation:
  target emulation `elf64-littleriscv' does not match `elf32-littleriscv'
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: failed to merge target specific data of file /opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/libgcc.a(div.o)
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/v8/dwyhdmqn68bf9f2rm974l_lw0000gn/T//ccknxKLg.ltrans0.ltrans.o: in function `blitzSprite_TTRIS':
/Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:499:(.text.blitzSprite_TTRIS+0x48): undefined reference to `__mulsi3'
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:500:(.text.blitzSprite_TTRIS+0x60): undefined reference to `__mulsi3'
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:505:(.text.blitzSprite_TTRIS+0x8a): undefined reference to `__mulsi3'
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/v8/dwyhdmqn68bf9f2rm974l_lw0000gn/T//ccknxKLg.ltrans0.ltrans.o: in function `recupe_SCORES_TTRIS.part.0':
/Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:638:(.text.recupe_SCORES_TTRIS.part.0+0x4a): undefined reference to `__mulsi3'
/opt/homebrew/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/v8/dwyhdmqn68bf9f2rm974l_lw0000gn/T//ccknxKLg.ltrans0.ltrans.o: in function `main':
/Users/aeiche/Documents/Personal/Electronics Projects/CH32V003-GameConsole/software/tiny_tris/tiny_tris.c:362:(.text.startup.main+0x45e): undefined reference to `memset'
collect2: error: ld returned 1 exit status
make: *** [tiny_tris.elf] Error 1

I think it's clearly a linker issue, though I'm not really sure how to resolve it.

@wagiminator
Copy link
Owner

I have no idea at the moment ;-(

@wagiminator
Copy link
Owner

Did you perhaps use a different linker script or include other libraries? I don't know where the .text.startup.main comes from.

@TomatoCube18
Copy link

Not too sure if it is still an issue with aaroneiche
I have manage to compile through on a Mac Sequoia by linking to a "known working" libgcc.

You can see the changes on Line 47 @ makefile
And the "known working" libgcc.a can be found here ~> libgcc.a

Hope it helps. 😃

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