Add branch relocation type
This commit is contained in:
@@ -41,7 +41,7 @@ import Language.Elna.Object.Elf
|
||||
)
|
||||
import System.IO (Handle)
|
||||
import qualified Language.Elna.Architecture.RiscV as RiscV
|
||||
import qualified Data.Text.Encoding as Text.Encoding
|
||||
import qualified Data.Text.Encoding as Text
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad.Trans.State (get)
|
||||
import Language.Elna.RiscV.CodeGenerator (Statement(..))
|
||||
@@ -238,7 +238,7 @@ riscv32Elf code objectHandle = text
|
||||
result =
|
||||
( encoded <> encoded'
|
||||
, relocations <> relocations'
|
||||
, ElfHeaderResult (names <> labelName <> "\0") (Vector.snoc symbols newEntry)
|
||||
, ElfHeaderResult (names <> Text.encodeUtf8 labelName <> "\0") (Vector.snoc symbols newEntry)
|
||||
, definitions'
|
||||
)
|
||||
in encodeAsm shndx result rest'
|
||||
@@ -248,18 +248,21 @@ riscv32Elf code objectHandle = text
|
||||
let offset = fromIntegral $ LazyByteString.length encoded
|
||||
unresolvedRelocation = case instruction of
|
||||
RiscV.RelocatableInstruction _ instructionType
|
||||
| RiscV.Higher20 _ symbolName <- instructionType
|
||||
| RiscV.RHigher20 _ symbolName <- instructionType
|
||||
-> Just -- R_RISCV_HI20
|
||||
$ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 26
|
||||
| RiscV.Lower12I _ _ _ symbolName <- instructionType
|
||||
$ UnresolvedRelocation (Text.encodeUtf8 symbolName) offset 26
|
||||
| RiscV.RLower12I _ _ _ symbolName <- instructionType
|
||||
-> Just -- R_RISCV_LO12_I
|
||||
$ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 27
|
||||
| RiscV.Lower12S symbolName _ _ _ <- instructionType
|
||||
$ UnresolvedRelocation (Text.encodeUtf8 symbolName) offset 27
|
||||
| RiscV.RLower12S symbolName _ _ _ <- instructionType
|
||||
-> Just -- R_RISCV_LO12_S
|
||||
$ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 28
|
||||
$ UnresolvedRelocation (Text.encodeUtf8 symbolName) offset 28
|
||||
| RiscV.RBranch symbolName _ _ _ <- instructionType
|
||||
-> Just -- R_RISCV_BRANCH
|
||||
$ UnresolvedRelocation (Text.encodeUtf8 symbolName) offset 16
|
||||
RiscV.CallInstruction symbolName
|
||||
-> Just -- R_RISCV_CALL_PLT
|
||||
$ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 19
|
||||
$ UnresolvedRelocation (Text.encodeUtf8 symbolName) offset 19
|
||||
RiscV.BaseInstruction _ _ -> Nothing
|
||||
chunk = ByteString.Builder.toLazyByteString
|
||||
$ RiscV.instruction instruction
|
||||
@@ -270,7 +273,7 @@ riscv32Elf code objectHandle = text
|
||||
, addDefinition unresolvedRelocation definitions
|
||||
)
|
||||
in encodeInstructions result
|
||||
| otherwise = (encoded, relocations, Vector.drop 1 instructions, definitions)
|
||||
| otherwise = (encoded, relocations, instructions, definitions)
|
||||
addDefinition (Just (UnresolvedRelocation symbolName _ _)) =
|
||||
HashSet.insert symbolName
|
||||
addDefinition Nothing = id
|
||||
|
||||
Reference in New Issue
Block a user