From abb6fbfe333173acfeeb9304f9c529778e58ff1c Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 16 Apr 2011 08:20:45 +0000 Subject: Preliminary support for 'aligned' and 'section' attributes, gcc-style. New-style handling of sections for IA32 and ARM. Work in progress, to be tested. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1635 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- common/Sections.ml | 53 ++++++++++++++++++++++++++++++++++++++++++----------- common/Sections.mli | 4 ++-- 2 files changed, 44 insertions(+), 13 deletions(-) (limited to 'common') diff --git a/common/Sections.ml b/common/Sections.ml index 9124f85..f37144a 100644 --- a/common/Sections.ml +++ b/common/Sections.ml @@ -14,6 +14,7 @@ (* *********************************************************************) open Camlcoq +open Cparser module StringMap = Map.Make(String) @@ -165,19 +166,50 @@ let default_use_section id name = assert ok end -let define_function id = - default_use_section id "CODE" +(* Associate an undeclared section to a global symbol, GCC-style *) + +let use_gcc_section id name readonly exec = + Hashtbl.add section_table_at_def id !current_section_table; + let sn = Section_user(name, not readonly, exec) in + let si = { sec_name_init = sn; sec_name_uninit = sn; + sec_writable = not readonly; sec_executable = exec; + sec_near_access = false } in + Hashtbl.add use_section_table id si + +(* Record sections for a variable definition *) + +let define_variable env id ty = + let attr = Cutil.attributes_of_type env ty in + let readonly = List.mem C.AConst attr && not(List.mem C.AVolatile attr) in + (* Check for a GCC-style "section" attribute *) + match Cutil.find_custom_attributes ["section"; "__section__"] attr with + | [[C.AString name]] -> + (* Use gcc-style section *) + use_gcc_section id name readonly false + | _ -> + (* Use default section appropriate for size and const-ness *) + let size = match Cutil.sizeof env ty with Some sz -> sz | None -> max_int in + default_use_section id + (if readonly + then if size <= !Clflags.option_small_const then "SCONST" else "CONST" + else if size <= !Clflags.option_small_data then "SDATA" else "DATA") + +(* Record sections for a function definition *) + +let define_function env id ty_res = + let attr = Cutil.attributes_of_type env ty_res in + match Cutil.find_custom_attributes ["section"; "__section__"] attr with + | [[C.AString name]] -> + use_gcc_section id name true true + | _ -> + default_use_section id "CODE" + +(* Record sections for a string literal *) let define_stringlit id = default_use_section id "STRING" -let define_variable id size readonly = - default_use_section id - (if readonly - then if size <= !Clflags.option_small_const then "SCONST" else "CONST" - else if size <= !Clflags.option_small_data then "SDATA" else "DATA") - -(* Determine section to use for a variable definition *) +(* Determine section to use for a variable *) let section_for_variable a initialized = try @@ -186,8 +218,7 @@ let section_for_variable a initialized = with Not_found -> Section_data initialized -(* Determine (text, literal, jumptable) sections to use - for a function definition *) +(* Determine (text, literal, jumptable) sections to use for a function *) let sections_for_function a = let s_text = diff --git a/common/Sections.mli b/common/Sections.mli index 090d4bb..c6a7c96 100644 --- a/common/Sections.mli +++ b/common/Sections.mli @@ -34,8 +34,8 @@ val define_section: -> ?writable:bool -> ?executable:bool -> ?near:bool -> unit -> unit val use_section_for: AST.ident -> string -> bool -val define_function: AST.ident -> unit -val define_variable: AST.ident -> int -> bool -> unit +val define_function: Cparser.Env.t -> AST.ident -> Cparser.C.typ -> unit +val define_variable: Cparser.Env.t -> AST.ident -> Cparser.C.typ -> unit val define_stringlit: AST.ident -> unit val section_for_variable: AST.ident -> bool -> section_name -- cgit v1.2.3