Skip to content

Add ability to output raw binary #4291

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

Merged
merged 1 commit into from
Feb 3, 2020

Conversation

mlarouche
Copy link
Contributor

@mlarouche mlarouche commented Jan 26, 2020

Add InstallRawStep to Zig build system that does a similar job to llvm-objcopy. To use it, do

exe.installRaw("kernel.bin");'

where exe is a LibExeObjStep

Part of #2826

See commit wendigojaeger/ZigGBA@4f7ffdc for an example of usage with the build system

@LemonBoy
Copy link
Contributor

Isn't this better suited as a easy-to-use build step rather than as a compiler feature?
The whole implementation needs no data internal to the compiler and can be safely implemented in userspace as a pre-made build step the user can pick up and add to their own build process if needed.

@andrewrk
Copy link
Member

I agree with @LemonBoy here. A pure userland solution integrated with zig build would solve the real use case, and then later in the self hosted compiler it can take advantage of this code to integrate with the CLI. We can get away with stage1 not having CLI support for this. And we should get away with as minimal stage1 as possible to keep complexity under control.

@mlarouche
Copy link
Contributor Author

mlarouche commented Jan 26, 2020

I agree with @LemonBoy here. A pure userland solution integrated with zig build would solve the real use case, and then later in the self hosted compiler it can take advantage of this code to integrate with the CLI. We can get away with stage1 not having CLI support for this. And we should get away with as minimal stage1 as possible to keep complexity under control.

I'll change my PR to be userland-only in the zig build system

@daurnimator
Copy link
Contributor

See also the accepted proposal #2279 (comment)

@mlarouche mlarouche force-pushed the 2826_OutputRawBinary branch from 2329a72 to faa08c5 Compare February 1, 2020 22:54
…m-objcopy. To use it, do 'exe.installRaw("kernel.bin");' where exe is a LibExeObjStep

Part of ziglang#2826
@mlarouche mlarouche force-pushed the 2826_OutputRawBinary branch from faa08c5 to 7cc25a5 Compare February 1, 2020 22:55
@mlarouche
Copy link
Contributor Author

Pushed a new version with only build system code

Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Comment on lines +464 to +471
elf_program.p_type = @as(Elf64_Word, try in.readInt(Elf32_Word, elf.endian));
elf_program.p_offset = @as(Elf64_Off, try in.readInt(Elf32_Off, elf.endian));
elf_program.p_vaddr = @as(Elf64_Addr, try in.readInt(Elf32_Addr, elf.endian));
elf_program.p_paddr = @as(Elf64_Addr, try in.readInt(Elf32_Addr, elf.endian));
elf_program.p_filesz = @as(Elf64_Word, try in.readInt(Elf32_Word, elf.endian));
elf_program.p_memsz = @as(Elf64_Word, try in.readInt(Elf32_Word, elf.endian));
elf_program.p_flags = @as(Elf64_Word, try in.readInt(Elf32_Word, elf.endian));
elf_program.p_align = @as(Elf64_Word, try in.readInt(Elf32_Word, elf.endian));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all these @as are superfluous.

elf_section.sh_link = try in.readInt(u32, elf.endian);
elf_section.sh_info = try in.readInt(u32, elf.endian);
elf_section.sh_addralign = @as(u64, try in.readInt(u32, elf.endian));
elf_section.sh_entsize = @as(u64, try in.readInt(u32, elf.endian));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this TODO comment can be deleted and the @as can be removed

@andrewrk andrewrk merged commit 9b11e5e into ziglang:master Feb 3, 2020
@mlarouche mlarouche deleted the 2826_OutputRawBinary branch February 4, 2020 01:45
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

Successfully merging this pull request may close these issues.

4 participants