Skip to content

Commit

Permalink
pass ci
Browse files Browse the repository at this point in the history
  • Loading branch information
katsyoshi committed Sep 13, 2023
1 parent 4b83552 commit a68eb23
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/vaporware/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",]
Expand Down
6 changes: 6 additions & 0 deletions lib/vaporware/compiler/assembler/elf/section/bss.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Vaporware::Compiler::Assembler::ELF::Section::BSS

def build = bytes.flatten.pack("C*")
private
def bytes = []
end
6 changes: 6 additions & 0 deletions lib/vaporware/compiler/assembler/elf/section/data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Vaporware::Compiler::Assembler::ELF::Section::Data

def build = bytes.flatten.pack("C*")
private
def bytes = []
end
6 changes: 3 additions & 3 deletions lib/vaporware/compiler/assembler/elf/section/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 6 additions & 0 deletions lib/vaporware/compiler/assembler/elf/section/shstrtab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Vaporware::Compiler::Assembler::ELF::Section::Strtab

def build = bytes.flatten.pack("C*")
private
def bytes = []
end
2 changes: 2 additions & 0 deletions lib/vaporware/compiler/assembler/elf/section/shsymtab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Vaporware::Compiler::Assembler::ELF::Section::Shsymtab
end
2 changes: 1 addition & 1 deletion lib/vaporware/compiler/assembler/elf/section/symtab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/vaporware/compiler/assembler/elf/section_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,]
Expand Down
10 changes: 5 additions & 5 deletions sig/vaporware/compiler/assembler/elf/header.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a68eb23

Please sign in to comment.