diff --git a/lib/vaporware/compiler.rb b/lib/vaporware/compiler.rb index 2796d31..1ff8604 100644 --- a/lib/vaporware/compiler.rb +++ b/lib/vaporware/compiler.rb @@ -31,7 +31,7 @@ def assemble(input:, output: File.basename(input, ".*") + ".o", assembler: "as", output end - def link(input:, output: File.basename(input, ".*"), linker: "mold", linker_options: [], dyn_ld_path: ["-dynamic-linker", "/lib64/ld-linux-x86-64.so.2"], ld_path: ["/lib64/libc.so.6", "/usr/lib64/crt1.o"], shared: false) + def link(input:, output: File.basename(input, ".*"), linker: "ld", linker_options: [], dyn_ld_path: ["-dynamic-linker", "/lib64/ld-linux-x86-64.so.2"], ld_path: ["/lib64/libc.so.6", "/usr/lib64/crt1.o"], shared: false) if shared dyn_ld_path = [] ld_path = ["/usr/lib64/crti.o", "/usr/lib/gcc/x86_64-pc-linux-gnu/13/crtbeginS.o", "/usr/lib/gcc/x86_64-pc-linux-gnu/13/crtendS.o", "/usr/lib64/crtn.o",] diff --git a/lib/vaporware/compiler/assembler/elf/section/bss.rb b/lib/vaporware/compiler/assembler/elf/section/bss.rb new file mode 100644 index 0000000..6ced12c --- /dev/null +++ b/lib/vaporware/compiler/assembler/elf/section/bss.rb @@ -0,0 +1,6 @@ +class Vaporware::Compiler::Assembler::ELF::Section::BSS + + def build = bytes.flatten.pack("C*") + private + def bytes = [] +end diff --git a/lib/vaporware/compiler/assembler/elf/section/data.rb b/lib/vaporware/compiler/assembler/elf/section/data.rb new file mode 100644 index 0000000..7b99987 --- /dev/null +++ b/lib/vaporware/compiler/assembler/elf/section/data.rb @@ -0,0 +1,6 @@ +class Vaporware::Compiler::Assembler::ELF::Section::Data + + def build = bytes.flatten.pack("C*") + private + def bytes = [] +end diff --git a/lib/vaporware/compiler/assembler/elf/section/note.rb b/lib/vaporware/compiler/assembler/elf/section/note.rb index 49f83c0..ea83ceb 100644 --- a/lib/vaporware/compiler/assembler/elf/section/note.rb +++ b/lib/vaporware/compiler/assembler/elf/section/note.rb @@ -14,7 +14,7 @@ def initialize def set!(nsize: nil, dsize: nil, type: nil, name: nil, desc: nil) @nsize = num2bytes(nsize, 4) if check(nsize, 4) - @dsize = num2bytes(dsize, 4) if check(disze, 4) + @dsize = num2bytes(dsize, 4) if check(dsize, 4) @type = num2bytes(type, 4) if check(type, 4) @name = name!(name) if name @desc = desc!(desc) if desc @@ -26,10 +26,10 @@ def build = bytes.flatten.pack("C*") private def name!(name) = align!(@name = name.bytes, 4) - def desc!(desc) = align!(@desc = desc.bytes, 4) + def desc!(desc) = align!(@desc = desc.is_a?(Array) ? desc : desc.bytes, 4) def bytes = [@nsize, @dsize, @type, @name, @desc] def align!(val, bytes) = (val << 0 until val.size % bytes == 0) - def num2bytes(val, bytes) = ("%0#{bytes}x" % val).scan(/.{1,2}/).map { |v| v.to_i(16) }.revert + def num2bytes(val, bytes) = ("%0#{bytes}x" % val).scan(/.{1,2}/).map { |v| v.to_i(16) }.reverse def check(val, bytes) = (val.is_a?(Array) && val.all? { |v| v.is_a?(Integer) } && val.size == bytes) || val.is_a?(Integer) end diff --git a/lib/vaporware/compiler/assembler/elf/section/shstrtab.rb b/lib/vaporware/compiler/assembler/elf/section/shstrtab.rb new file mode 100644 index 0000000..c7f75e4 --- /dev/null +++ b/lib/vaporware/compiler/assembler/elf/section/shstrtab.rb @@ -0,0 +1,6 @@ +class Vaporware::Compiler::Assembler::ELF::Section::Strtab + + def build = bytes.flatten.pack("C*") + private + def bytes = [] +end diff --git a/lib/vaporware/compiler/assembler/elf/section/shsymtab.rb b/lib/vaporware/compiler/assembler/elf/section/shsymtab.rb new file mode 100644 index 0000000..2e0401f --- /dev/null +++ b/lib/vaporware/compiler/assembler/elf/section/shsymtab.rb @@ -0,0 +1,2 @@ +class Vaporware::Compiler::Assembler::ELF::Section::Shsymtab +end diff --git a/lib/vaporware/compiler/assembler/elf/section/symtab.rb b/lib/vaporware/compiler/assembler/elf/section/symtab.rb index 0e67f02..6414755 100644 --- a/lib/vaporware/compiler/assembler/elf/section/symtab.rb +++ b/lib/vaporware/compiler/assembler/elf/section/symtab.rb @@ -21,6 +21,6 @@ def set!(name: nil, info: nil, other: nil, shndx: nil, value: nil, size: nil) private def bytes = [@name, @info, @other, @shndx, @value, @size] - def num2bytes(val, bytes) = ("%0#{bytes}x" % val).scan(/.{1,2}/).map { |v| v.to_i(16) }.revert + def num2bytes(val, bytes) = ("%0#{bytes}x" % val).scan(/.{1,2}/).map { |v| v.to_i(16) }.reverse def check(val, bytes) = (val.is_a?(Array) && val.all? { |v| v.is_a?(Integer) } && val.size == bytes) || val.is_a?(Integer) end diff --git a/lib/vaporware/compiler/assembler/elf/section_header.rb b/lib/vaporware/compiler/assembler/elf/section_header.rb index e05b2e7..de9ef98 100644 --- a/lib/vaporware/compiler/assembler/elf/section_header.rb +++ b/lib/vaporware/compiler/assembler/elf/section_header.rb @@ -32,6 +32,11 @@ def set!(name: nil, type: nil, flags: nil, addr: nil, def null! = set!(name: 0, type: 0, flags: 0, addr: 0, offset: 0, size: 0, link: 0, info: 0, addralign: 0, entsize: 0) def text! = set!(flags: 0x06, addralign: 0x01) def note! = set!(type: 0x07, flags: 0x02, size: 0x30, addralign: 0x08) + def data! = set! + def symtab! = set! + def strtab! = set! + def bss! = set! + def shsymtab! = set! private def bytes = [@name, @type, @flags, @addr, @offset, @size, @link, @info, @addralign, @entsize,] diff --git a/sig/vaporware/compiler/assembler/elf/header.rbs b/sig/vaporware/compiler/assembler/elf/header.rbs index fdea5a2..af8ceca 100644 --- a/sig/vaporware/compiler/assembler/elf/header.rbs +++ b/sig/vaporware/compiler/assembler/elf/header.rbs @@ -6,16 +6,16 @@ class Vaporware::Compiler::Assembler::ELF::Header @type: Integer @arch: Array[Integer] @version: Array[Integer] - @entry: Array[Integer] | nil - @phoffset: Array[Integer] | nil - @shoffset: Array[Integer] | nil + @entry: Array[Integer]? + @phoffset: Array[Integer]? + @shoffset: Array[Integer]? @flags: Array[Integer] @ehsize: Array[Integer] @phsize: Array[Integer] @ehnum: Array[Integer] @shentsize: Array[Integer] - @shnum: Array[Integer] | nil - @shstrndx: Array[Integer] | nil + @shnum: Array[Integer]? + @shstrndx: Array[Integer]? def initialize: (?endian: Symbol, ?type: Symbol, ?arche: Symbol) -> void def build: () -> String