Commit 9f1cb84a authored by John's avatar John

add linker calling convention (:convention: before linker file name) for Unix and MacOSX

parent 980e5666
Pipeline #39238 failed with stage
in 53 seconds
......@@ -404,8 +404,8 @@ Link linker winfun path
applicationOptions=:{ss,hs,initial_heap_size,profiling,heap_size_multiple,o,memoryProfilingMinimumHeapSize=minheap}
optionspathname library_file_names object_file_names static_libraries static gen_relocs gen_symbol_table gen_linkmap
link_resources resource_path gen_dll dll_syms startupdir dynlstr _ use_64_bit_processor ps
# (calling_convention,linker) = get_optional_calling_convention linker
# (linker,linkerdir,options1,options2) = get_path_name_and_options2 linker startupdir
# flags = ApplicationOptionsToFlags applicationOptions
# optdirpath = RemoveFilename optionspathname
# ((ok,pd_optdirpath),ps) = pd_StringToPath optdirpath ps
......@@ -420,61 +420,93 @@ Link linker winfun path
# (options_file_ok,ps) = accFiles (write_options_file optionspathname flags hs ss initial_heap_size heap_size_multiple minheap use_64_bit_processor) ps
| not options_file_ok
= (winfun ["Linker error: Could not write the options object file: "+++optionspathname] ps,False)
# is_gcc = linker == "/usr/bin/gcc"
# linkopts =
{ exe_path = path
, res_path = resource_path
, open_console = o <> NoConsole
, static_link = static
, gen_relocs = gen_relocs
, gen_symbol_table = gen_symbol_table
, gen_linkmap = gen_linkmap
, link_resources = link_resources
, object_paths = optionspathname :! (RemoveDup object_file_names)
, dynamic_libs = RemoveDup library_file_names
, static_libs = RemoveDup static_libraries
, stack_size = ss
, gen_dll = gen_dll
, dll_names = dll_syms
, dynamics_path = startupdir +++. DirSeparatorString +++. dynlstr
, lib_name_obj_path = MakeFullPathname tooltempdir "lib_name.o"
}
# linkoptspath = MakeFullPathname tooltempdir "linkopts"
# linkerrspath = MakeFullPathname tooltempdir "linkerrs"
# (err,ps) = if is_gcc (Nothing,ps) (accFiles (WriteLinkOpts linkoptspath linkopts) ps)
| isJust err
= (winfun (fromJust err) ps,False)
# linker_args = if is_gcc
//Options2 are for the actual linker (gcc/clang)
["-s","-o", path: [optionspathname : StrictListToList (RemoveDup object_file_names)]++add_options_string_to_args 0 options2 (StrictListToList library_file_names)]
//Options1 are only for clean linkers (e.g. bigger heap for the linker itself)
(add_options_string_to_args 0 options1 ["-I",linkoptspath,"-O",linkerrspath])
# (argv,args_memory) = make_argv [linker:linker_args]
# ld_pid = fork
| ld_pid<0
= abort "fork failed\n"
| ld_pid==0
| execv (linker+++"\0") argv<0
= abort ("execv failed: Could not run '" +++ linker +++ "'\n")
= abort "execution continued after execv\n"
| free args_memory<0
= abort "free failed\n"
# (w_pid,status) = wait_pid ld_pid 0
| w_pid <> -1 && w_pid<>ld_pid
= abort "waitpid failed\n"
# result = (status bitand 0xff00) >> 8
# wtermsig = status bitand 0x7f
| wtermsig<>0
= abort "linker exited abnormally\n"
# link_ok = result>=0
//Read link errors
# ((err,link_errors),ps) = if is_gcc ((Nothing,[]),ps) (accFiles (ReadLinkErrors linkerrspath) ps)
| isJust err
= (winfun (fromJust err) ps,False)
# (errtext,errlines) = (link_errors, length link_errors)
| errlines<>0
= (winfun errtext ps,link_ok)
= (ps,link_ok)
| size calling_convention==0
| linker=="/usr/bin/gcc"
= linkGCC options2 ps
= linkLinker options1 ps
| calling_convention=="gcc"
= linkGCC options2 ps
| calling_convention=="linker"
= linkLinker options1 ps
= (winfun ["Linker error: Unknown calling convention : "+++calling_convention] ps,False)
where
linkGCC options2 ps
# linker_args =
//Options2 are for the actual linker (gcc/clang)
["-s","-o", path: [optionspathname : StrictListToList (RemoveDup object_file_names)]++add_options_string_to_args 0 options2 (StrictListToList library_file_names)]
# (argv,args_memory) = make_argv [linker:linker_args]
# ld_pid = fork
| ld_pid<0
= abort "fork failed\n"
| ld_pid==0
| execv (linker+++"\0") argv<0
= abort ("execv failed: Could not run '" +++ linker +++ "'\n")
= abort "execution continued after execv\n"
| free args_memory<0
= abort "free failed\n"
# (w_pid,status) = wait_pid ld_pid 0
| w_pid <> -1 && w_pid<>ld_pid
= abort "waitpid failed\n"
# result = (status bitand 0xff00) >> 8
# wtermsig = status bitand 0x7f
| wtermsig<>0
= abort "linker exited abnormally\n"
# link_ok = result>=0
= (ps,link_ok)
linkLinker options1 ps
# linkopts =
{ exe_path = path
, res_path = resource_path
, open_console = o <> NoConsole
, static_link = static
, gen_relocs = gen_relocs
, gen_symbol_table = gen_symbol_table
, gen_linkmap = gen_linkmap
, link_resources = link_resources
, object_paths = optionspathname :! (RemoveDup object_file_names)
, dynamic_libs = RemoveDup library_file_names
, static_libs = RemoveDup static_libraries
, stack_size = ss
, gen_dll = gen_dll
, dll_names = dll_syms
, dynamics_path = startupdir +++. DirSeparatorString +++. dynlstr
, lib_name_obj_path = MakeFullPathname tooltempdir "lib_name.o"
}
# linkoptspath = MakeFullPathname tooltempdir "linkopts"
# linkerrspath = MakeFullPathname tooltempdir "linkerrs"
# (err,ps) = accFiles (WriteLinkOpts linkoptspath linkopts) ps
| isJust err
= (winfun (fromJust err) ps,False)
# linker_args =
//Options1 are only for clean linkers (e.g. bigger heap for the linker itself)
add_options_string_to_args 0 options1 ["-I",linkoptspath,"-O",linkerrspath]
# (argv,args_memory) = make_argv [linker:linker_args]
# ld_pid = fork
| ld_pid<0
= abort "fork failed\n"
| ld_pid==0
| execv (linker+++"\0") argv<0
= abort ("execv failed: Could not run '" +++ linker +++ "'\n")
= abort "execution continued after execv\n"
| free args_memory<0
= abort "free failed\n"
# (w_pid,status) = wait_pid ld_pid 0
| w_pid <> -1 && w_pid<>ld_pid
= abort "waitpid failed\n"
# result = (status bitand 0xff00) >> 8
# wtermsig = status bitand 0x7f
| wtermsig<>0
= abort "linker exited abnormally\n"
# link_ok = result>=0
//Read link errors
# ((err,link_errors),ps) = accFiles (ReadLinkErrors linkerrspath) ps
| isJust err
= (winfun (fromJust err) ps,False)
# (errtext,errlines) = (link_errors, length link_errors)
| errlines<>0
= (winfun errtext ps,link_ok)
= (ps,link_ok)
DelayEventLoop :: !.ps -> .ps
DelayEventLoop ps
......@@ -682,6 +714,16 @@ errors_file_path temp_dir slot
= temp_dir +++ DirSeparatorString +++ "errors"
= temp_dir +++ DirSeparatorString +++ "errors"+++toString slot
get_optional_calling_convention :: !{#Char} -> (!{#Char},!{#Char})
get_optional_calling_convention s
# s_size = size s;
| s_size>0 && s.[0]==':'
# next_c = FindColonChar 1 s s_size
| next_c<s_size
= (s % (1,next_c-1),s % (next_c+1,s_size));
= ("",s);
= ("",s);
get_path_name_and_options2 ccstring startupdir
# (ccstring,rem) = splitOptions ccstring
(opts,opts`) = splitOptions rem
......@@ -702,20 +744,18 @@ get_path_name_and_options codegen_or_linker startupdir
splitOptions :: !{#Char} -> (!{#Char},!{#Char})
splitOptions str
# len_str = size str
first_q = FindQuoteChar str len_str 0
| first_q >= len_str
first_c = FindColonChar 0 str len_str
| first_c >= len_str
= (str,"")
# first_str = str % (0,dec first_q)
last_str = str % (first_q+1, len_str)
# first_str = str % (0,dec first_c)
last_str = str % (first_c+1, len_str)
= (first_str,last_str)
where
FindQuoteChar str len pos = FindChar ':' str len pos;
FindChar :: !Char !.String !.Int !Int -> Int;
FindChar c line linelen pos
| pos >= linelen = pos;
| c == line.[pos] = pos;
= FindChar c line linelen (pos+1);
FindColonChar :: !Int !String !Int -> Int;
FindColonChar pos line linelen
| pos<linelen && line.[pos]<>'.'
= FindColonChar (pos+1) line linelen;
= pos;
add_options_string_to_args :: !Int !{#Char} ![{#Char}] -> [{#Char}]
add_options_string_to_args i s args
......
......@@ -376,6 +376,7 @@ Link linker winfun path
applicationOptions=:{ss,hs,initial_heap_size,profiling,heap_size_multiple,o,memoryProfilingMinimumHeapSize=minheap}
optionspathname library_file_names object_file_names static_libraries static gen_relocs gen_symbol_table gen_linkmap
link_resources resource_path gen_dll dll_syms startupdir dynlstr _ use_64_bit_processor ps
# (calling_convention,linker) = get_optional_calling_convention linker
# (linker,linker_dir,options1,options2) = get_path_name_and_options2 linker startupdir
# flags = ApplicationOptionsToFlags applicationOptions
optdirpath = RemoveFilename optionspathname
......@@ -392,12 +393,19 @@ Link linker winfun path
| not options_file_ok
= (winfun ["Linker error: Could not write the options object file: "+++optionspathname] ps,False)
# object_paths = [optionspathname : StrictListToList (RemoveDup object_file_names)]
# len = size linker
| len >= 14 && linker % (len - 14, len) == "lib/exe/linker"
= linkOptimizingGCC linker object_paths options1 options2 ps
| len >= 12 && linker % (len - 12, len) == "/usr/bin/gcc"
# len = size linker
| len >= 14 && linker % (len - 14, len) == "lib/exe/linker"
= linkOptimizingGCC linker object_paths options1 options2 ps
| len >= 12 && linker % (len - 12, len) == "/usr/bin/gcc"
= linkGCC object_paths options2 ps
= linkOther linker object_paths ps
| calling_convention=="gcc"
= linkGCC object_paths options2 ps
| calling_convention=="linker"
= linkOther linker object_paths ps
| calling_convention=="linker+gcc"
= linkOptimizingGCC linker object_paths options1 options2 ps
= (winfun ["Linker error: Unknown calling convention : "+++calling_convention] ps,False)
where
//First call the optimizing linker to generate an intermediate optimized object file which is then passed to gcc
linkOptimizingGCC linker object_paths options1 options2 ps
......@@ -719,6 +727,16 @@ errors_file_path temp_dir slot
= temp_dir +++ DirSeparatorString +++ "errors"
= temp_dir +++ DirSeparatorString +++ "errors"+++toString slot
get_optional_calling_convention :: !{#Char} -> (!{#Char},!{#Char})
get_optional_calling_convention s
# s_size = size s;
| s_size>0 && s.[0]==':'
# next_c = FindColonChar 1 s s_size
| next_c<s_size
= (s % (1,next_c-1),s % (next_c+1,s_size));
= ("",s);
= ("",s);
get_path_name_and_options2 ccstring startupdir
# (ccstring,rem) = splitOptions ccstring
(opts,opts`) = splitOptions rem
......@@ -738,20 +756,18 @@ get_path_name_and_options codegen_or_linker startupdir
splitOptions :: !{#Char} -> (!{#Char},!{#Char})
splitOptions str
# len_str = size str
first_q = FindQuoteChar str len_str 0
| first_q >= len_str
first_c = FindColonChar 0 str len_str
| first_c >= len_str
= (str,"")
# first_str = str % (0,dec first_q)
last_str = str % (first_q+1, len_str)
# first_str = str % (0,dec first_c)
last_str = str % (first_c+1, len_str)
= (first_str,last_str)
where
FindQuoteChar str len pos = FindChar ':' str len pos;
FindChar :: !Char !.String !.Int !Int -> Int;
FindChar c line linelen pos
| pos >= linelen = pos;
| c == line.[pos] = pos;
= FindChar c line linelen (pos+1);
FindColonChar :: !Int !String !Int -> Int;
FindColonChar pos line linelen
| pos<linelen && line.[pos]<>'.'
= FindColonChar (pos+1) line linelen;
= pos;
add_options_string_to_args :: !Int !{#Char} ![{#Char}] -> [{#Char}]
add_options_string_to_args i s args
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment