as: handle the .rodata section

This commit is contained in:
Mikael Pettersson
2020-01-03 21:41:52 +01:00
parent 8d2b402d69
commit e144176d1c
3 changed files with 50 additions and 1 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
.section .text,"ax",@progbits
.globl foo
.type foo,@function
foo:
popj 017,
.size foo,.-foo
.section .rodata,"a",@progbits
bar: .long 42

View File

@@ -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

View File

@@ -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, []}