Skip to content

Implement ELF toolchain based on GNU toolchain codes #7

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

Open
wants to merge 2 commits into
base: z80
Choose a base branch
from

Conversation

atirut-w
Copy link

This allows Clang to directly use z80-elf binutils toolchain for assembling and linking.

$ ./bin/clang -target z80-elf -nostartfiles -nostdlib test.c
/usr/bin/z80-elf-ld: warning: cannot find entry symbol _start; defaulting to 00000100

(The warning is also present when assembling and linking manually with the binutils toolchain)

Note

The standard executable linking with runtime object files can't really be tested without a complete Z80 sysroot, and I am not sure how to build one. Right now, you need to use -nostartfiles -nostdlib to compile executables. The PR works completely fine otherwise.

@adriweb
Copy link
Member

adriweb commented Jul 31, 2025

Does this take over the default "mode of operation" so far, especially for eZ80? Or does it have to be triggered manually.
Because most importantly we shouldn't break the current behavior of the ez80-clang at least.

@atirut-w
Copy link
Author

atirut-w commented Jul 31, 2025

Ah, that's something to fix, then. The toolchain driver does the following so that GAS doesn't error out:

void Z80ToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
                                        llvm::opt::ArgStringList &CC1Args,
                                        Action::OffloadKind) const {
  // Add -mllvm --z80-gas-style by default
  CC1Args.push_back("-mllvm");
  CC1Args.push_back("--z80-gas-style");
}

Any idea on how I should make it backward-compatible?

@adriweb
Copy link
Member

adriweb commented Jul 31, 2025

Not sure how to do that, but somehow trigger all the new things only if there's some specific option?

@atirut-w
Copy link
Author

That means you'd need another flag to make Clang compile, assemble, and link in one step. It should be as easy as a quick one-line edit, but I'm not sure about the UX.

@adriweb
Copy link
Member

adriweb commented Jul 31, 2025

Well, considering this repo is intended for the CE toolchain primarily, it seems like the good choice until the CE toolchain adopts a GNU-toolchain-compatibility thing by default.
Then the old (current) behavior can become the one with a flag instead, I guess.

@atirut-w
Copy link
Author

I'll do that real quick then

@atirut-w
Copy link
Author

Okay, it seems I can't just add a new option as simply as adding a new global for Clang. I guess having the user manually add -mllvm --z80-gas-style is fine for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants