From e144176d1c2287fa83b83546b64702d3a4b12558 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 3 Jan 2020 21:41:52 +0100 Subject: [PATCH] as: handle the .rodata section --- erlang/apps/as/priv/test7.s | 29 +++++++++++++++++++++++++++++ erlang/apps/as/src/assemble.erl | 6 +++++- erlang/apps/as/src/input.erl | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 erlang/apps/as/priv/test7.s diff --git a/erlang/apps/as/priv/test7.s b/erlang/apps/as/priv/test7.s new file mode 100644 index 0000000..332dd13 --- /dev/null +++ b/erlang/apps/as/priv/test7.s @@ -0,0 +1,29 @@ +/* + * test7.s + * Copyright (C) 2020 Mikael Pettersson + * + * This file is part of pdp10-tools. + * + * pdp10-tools is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * pdp10-tools is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with pdp10-tools. If not, see . + */ + + .section .text,"ax",@progbits + .globl foo + .type foo,@function +foo: + popj 017, + .size foo,.-foo + + .section .rodata,"a",@progbits +bar: .long 42 diff --git a/erlang/apps/as/src/assemble.erl b/erlang/apps/as/src/assemble.erl index 815b322..3ca7454 100644 --- a/erlang/apps/as/src/assemble.erl +++ b/erlang/apps/as/src/assemble.erl @@ -1,7 +1,7 @@ %%% -*- erlang-indent-level: 2 -*- %%% %%% sections assembler for pdp10-elf as -%%% Copyright (C) 2013-2019 Mikael Pettersson +%%% Copyright (C) 2013-2020 Mikael Pettersson %%% %%% This file is part of pdp10-tools. %%% @@ -44,6 +44,10 @@ section(Section, Tunit) -> , sh_type = ?SHT_PROGBITS , sh_flags = ?SHF_ALLOC bor ?SHF_WRITE } -> stmts(Section, Tunit); + #section{ name = ".rodata" ++ _ + , sh_type = ?SHT_PROGBITS + , sh_flags = ?SHF_ALLOC + } -> stmts(Section, Tunit); #section{ name = ".text" ++ _ , sh_type = ?SHT_PROGBITS , sh_flags = ?SHF_ALLOC bor ?SHF_EXECINSTR diff --git a/erlang/apps/as/src/input.erl b/erlang/apps/as/src/input.erl index 21bd137..8fbf0da 100644 --- a/erlang/apps/as/src/input.erl +++ b/erlang/apps/as/src/input.erl @@ -404,6 +404,7 @@ pass2_sections([{SectionName, {Section, SubsectionsMap}} | Sections], Tunit0) -> pass2_subsections(SectionName, SubsectionsMap, Tunit) -> case SectionName of ".data" ++ _ -> ok; + ".rodata" ++ _ -> ok; ".text" ++ _ -> ok end, pass2_subsections(lists:sort(maps:to_list(SubsectionsMap)), Tunit). @@ -648,6 +649,7 @@ tunit_init() -> section_from_name(SectionName) -> case SectionName of ".data" -> section_dot_data(); + ".rodata" -> section_dot_rodata(); ".text" -> section_dot_text(); _ -> false end. @@ -680,6 +682,20 @@ section_dot_data() -> % ".data" , sh_entsize = 0 }. +section_dot_rodata() -> % ".rodata" + #section{ name = ".rodata" + , data = {stmts, []} + , dot = 0 + , shndx = 0 + , sh_name = 0 + , sh_type = ?SHT_PROGBITS + , sh_offset = 0 + , sh_flags = ?SHF_ALLOC + , sh_link = ?SHN_UNDEF + , sh_addralign = 4 % FIXME: target-specific + , sh_entsize = 0 + }. + section_dot_text() -> % ".text" #section{ name = ".text" , data = {stmts, []}