From 6226521abb84e72e62036bab4455a30758e2a1b6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 20 Apr 2014 02:28:57 +0300 Subject: [PATCH] figuring relocations --- lib/asm/arm/arm_assembler.rb | 6 ++++-- lib/asm/arm/code_generator.rb | 4 ++-- lib/asm/assembler.rb | 5 ----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/asm/arm/arm_assembler.rb b/lib/asm/arm/arm_assembler.rb index 8346df63..d71b7255 100644 --- a/lib/asm/arm/arm_assembler.rb +++ b/lib/asm/arm/arm_assembler.rb @@ -25,6 +25,9 @@ module Asm case type when R_ARM_PC24 diff = addr - io.tell - 8 + if (diff.abs > (1 << 25)) + raise Asm::AssemblyError.new('offset too large for R_ARM_PC24 relocation', nil) + end packed = [diff >> 2].pack('l') io << packed[0,3] when R_ARM_ABS32 @@ -33,8 +36,7 @@ module Asm when R_ARM_PC12 diff = addr - io.tell - 8 if (diff.abs > 2047) - raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation', - nil) + raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation', nil) end val = diff.abs diff --git a/lib/asm/arm/code_generator.rb b/lib/asm/arm/code_generator.rb index 449bc71a..792d0d0f 100644 --- a/lib/asm/arm/code_generator.rb +++ b/lib/asm/arm/code_generator.rb @@ -4,7 +4,7 @@ require_relative 'generator_label' require 'asm/nodes' require 'stream_reader' require 'stringio' - +require "asm/data_object" class Asm::Arm::CodeGenerator def initialize @@ -82,7 +82,7 @@ class Asm::Arm::CodeGenerator if (lbl = @externs.find { |extern| extern.name == sym }) lbl else - @externs << lbl = GeneratorExternLabel.new(sym) + @externs << lbl = Asm::Arm::GeneratorExternLabel.new(sym) @asm.add_object lbl lbl end diff --git a/lib/asm/assembler.rb b/lib/asm/assembler.rb index 2c949428..3a2a8d3f 100644 --- a/lib/asm/assembler.rb +++ b/lib/asm/assembler.rb @@ -8,7 +8,6 @@ module Asm def initialize @objects = [] @label_objects = [] - @label_callbacks = [] @relocations = [] end attr_reader :relocations, :objects @@ -21,10 +20,6 @@ module Asm @relocations << Asm::Relocation.new(*args) end - def register_label_callback(label, io_pos, &block) - @label_callbacks << [label, io_pos, block] - end - def assemble(io) @objects.each do |obj| obj.assemble io, self