Commit 6cb64fed authored by Haye Böhm's avatar Haye Böhm Committed by Mart Lubbers

Enables only using GCC

In some cases you do not want to use the built-in optimizing linker. You
can only use GCC by (for example):

    EnvironmentLinker:	/usr/bin/gcc::-g -lmysqlclient|... (other
    linkers)

Note that :: ensures the options are passed to gcc.
Co-authored-by: Mart Lubbers's avatarMart Lubbers <mart@martlubbers.net>
parent 376ad7a8
Pipeline #17649 passed with stage
in 53 seconds
...@@ -390,121 +390,124 @@ Link linker winfun path ...@@ -390,121 +390,124 @@ 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 # (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 | not options_file_ok
= (winfun ["Linker error: Could not write the options object file: "+++optionspathname] ps,False) = (winfun ["Linker error: Could not write the options object file: "+++optionspathname] ps,False)
# use_optimizing_linker_and_gcc = is_optimizing_linker linker # object_paths = [optionspathname : StrictListToList (RemoveDup object_file_names)]
| use_optimizing_linker_and_gcc # len = size linker
//First call the optimizing linker to generate an intermediate optimized object file which is then passed to gcc | len >= 14 && linker % (len - 14, len) == "lib/exe/linker"
# object_paths = [optionspathname : StrictListToList (RemoveDup object_file_names)] = linkOptimizingGCC linker object_paths options1 options2 ps
| len >= 12 && linker % (len - 12, len) == "/usr/bin/gcc"
# temp_file_name = "/tmp/linkerXXXXXX" +++ "\0" // +++ because modified by mkstemp = linkGCC object_paths options2 ps
# fd = mkstemp temp_file_name = linkOther linker object_paths ps
| fd== -1 where
= abort "mkstemp failed\n" //First call the optimizing linker to generate an intermediate optimized object file which is then passed to gcc
# r = close fd linkOptimizingGCC linker object_paths options1 options2 ps
| r== -1 # temp_file_name = "/tmp/linkerXXXXXX" +++ "\0" // +++ because modified by mkstemp
= abort "close failed\n" # fd = mkstemp temp_file_name
//Call optimized linker | fd== -1
# linker_args = add_options_string_to_args 0 options1 [temp_file_name:object_paths] = abort "mkstemp failed\n"
# (argv,args_memory) = make_argv [linker:linker_args] # r = close fd
| r== -1
# linker_pid = fork = abort "close failed\n"
| linker_pid<0 //Call optimized linker
= abort "fork failed\n" # linker_args = add_options_string_to_args 0 options1 [temp_file_name:object_paths]
| linker_pid==0 # (argv,args_memory) = make_argv [linker:linker_args]
| execv (linker+++"\0") argv<0
= abort "execv failed\n" # linker_pid = fork
= abort "execution continued after execv\n" | linker_pid<0
# (w_pid,status) = wait_pid linker_pid 0 = abort "fork failed\n"
| w_pid <> -1 && w_pid<>linker_pid | linker_pid==0
= abort "waitpid failed\n" | execv (linker+++"\0") argv<0
# exit_code = (status >> 8) bitand 0xff = abort "execv failed\n"
# wtermsig = status bitand 0x7f = abort "execution continued after execv\n"
| wtermsig<>0 # (w_pid,status) = wait_pid linker_pid 0
= abort "linker exited abnormally\n" | w_pid <> -1 && w_pid<>linker_pid
| free args_memory<0 = abort "waitpid failed\n"
= abort "free failed\n" # exit_code = (status >> 8) bitand 0xff
# wtermsig = status bitand 0x7f
# link_ok = exit_code==0 | wtermsig<>0
| not link_ok = abort "linker exited abnormally\n"
| unlink (temp_file_name+++"\0")<>0 | free args_memory<0
= (ps,link_ok) = abort "free failed\n"
= (ps,link_ok)
//Call gcc # link_ok = exit_code==0
# ld_args = ["-o",path,temp_file_name:add_options_string_to_args 0 options2 (StrictListToList (Append library_file_names "-lm"))] | not link_ok
ld_args = IF_MACOSX ld_args (IF_INT_64_OR_32 ["-no-pie":ld_args] ld_args)
ld_args = if gen_symbol_table ld_args ["-s":ld_args]
# ld = "/usr/bin/gcc"
# (argv,args_memory) = make_argv [ld:ld_args]
# ld_pid = fork
| ld_pid<0
= abort "fork failed\n"
| ld_pid==0
| execv (ld+++"\0") argv<0
= abort "execv failed\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"
# wtermsig = status bitand 0x7f
# exit_code = (status >> 8) bitand 0xff;
| wtermsig<>0
= abort "ld exited abnormally\n"
# link_ok = exit_code==0
| unlink (temp_file_name+++"\0")<>0 | unlink (temp_file_name+++"\0")<>0
= (ps,link_ok) = (ps,link_ok)
= (ps,link_ok) = (ps,link_ok)
| otherwise //Call gcc
//Call other/additional linker = linkGCC [temp_file_name] options2 ps
# linkopts =
{ exe_path = path //Just link with gcc
, res_path = resource_path linkGCC object_paths gccOptions ps
, open_console = o <> NoConsole # gcc_options = add_options_string_to_args 0 gccOptions (StrictListToList (Append library_file_names "-lm"))
, static_link = static # ld_args = ["-o", path : object_paths ] ++ gcc_options
, gen_relocs = gen_relocs ld_args = IF_MACOSX ld_args (IF_INT_64_OR_32 ["-no-pie":ld_args] ld_args)
, gen_symbol_table = gen_symbol_table ld_args = if gen_symbol_table ld_args ["-s":ld_args]
, gen_linkmap = gen_linkmap # ld = "/usr/bin/gcc"
, link_resources = link_resources # (argv,args_memory) = make_argv [ld:ld_args]
, object_paths = optionspathname :! (RemoveDup object_file_names) # ld_pid = fork
, dynamic_libs = RemoveDup library_file_names | ld_pid<0
, static_libs = RemoveDup static_libraries = abort "fork failed\n"
, stack_size = ss | ld_pid==0
, gen_dll = gen_dll | execv (ld+++"\0") argv<0
, dll_names = dll_syms = abort "execv failed\n"
, dynamics_path = startupdir +++. DirSeparatorString +++. dynlstr = abort "execution continued after execv\n"
, lib_name_obj_path = MakeFullPathname tooltempdir "lib_name.o" | free args_memory<0
} = abort "free failed\n"
# linkoptspath = MakeFullPathname tooltempdir "linkopts" # (w_pid,status) = wait_pid ld_pid 0
# linkerrspath = MakeFullPathname tooltempdir "linkerrs" | w_pid <> -1 && w_pid<>ld_pid
# (err,ps) = accFiles (WriteLinkOpts linkoptspath linkopts) ps = abort "waitpid failed\n"
| isJust err # wtermsig = status bitand 0x7f
= (winfun (fromJust err) ps,False) # exit_code = (status >> 8) bitand 0xff;
# linker_args = ["-I",linkoptspath,"-O",linkerrspath] | wtermsig<>0
# (argv,args_memory) = make_argv [linker:linker_args] = abort "ld exited abnormally\n"
# linker_pid = fork # link_ok = exit_code==0
| linker_pid<0 = (ps,link_ok)
= abort "fork failed\n"
| linker_pid==0 //Call other/additional linker
| execv (linker+++"\0") argv<0 linkOther linker object_paths ps
= abort "execv failed\n" # linkopts =
= abort "execution continued after execv\n" { exe_path = path
# (w_pid,status) = wait_pid linker_pid 0 , res_path = resource_path
| w_pid <> -1 && w_pid<>linker_pid , open_console = o <> NoConsole
= abort "waitpid failed\n" , static_link = static
# exit_code = (status >> 8) bitand 0xff , gen_relocs = gen_relocs
# wtermsig = status bitand 0x7f , gen_symbol_table = gen_symbol_table
| wtermsig<>0 , gen_linkmap = gen_linkmap
= abort "linker exited abnormally\n" , link_resources = link_resources
| free args_memory<0 , object_paths = ListToStrictList object_paths
= abort "free failed\n" , dynamic_libs = RemoveDup library_file_names
# link_ok = exit_code==0 , static_libs = RemoveDup static_libraries
= (ps,link_ok) , stack_size = ss
, gen_dll = gen_dll
is_optimizing_linker :: !{#Char} -> Bool , dll_names = dll_syms
is_optimizing_linker name , dynamics_path = startupdir +++. DirSeparatorString +++. dynlstr
# len = size name , lib_name_obj_path = MakeFullPathname tooltempdir "lib_name.o"
= len >= 14 && (name % (len - 14, len) == "lib/exe/linker") }
# linkoptspath = MakeFullPathname tooltempdir "linkopts"
# linkerrspath = MakeFullPathname tooltempdir "linkerrs"
# (err,ps) = accFiles (WriteLinkOpts linkoptspath linkopts) ps
| isJust err
= (winfun (fromJust err) ps,False)
# linker_args = ["-I",linkoptspath,"-O",linkerrspath]
# (argv,args_memory) = make_argv [linker:linker_args]
# linker_pid = fork
| linker_pid<0
= abort "fork failed\n"
| linker_pid==0
| execv (linker+++"\0") argv<0
= abort "execv failed\n"
= abort "execution continued after execv\n"
# (w_pid,status) = wait_pid linker_pid 0
| w_pid <> -1 && w_pid<>linker_pid
= abort "waitpid failed\n"
# exit_code = (status >> 8) bitand 0xff
# wtermsig = status bitand 0x7f
| wtermsig<>0
= abort "linker exited abnormally\n"
| free args_memory<0
= abort "free failed\n"
# link_ok = exit_code==0
= (ps,link_ok)
DelayEventLoop :: !.ps -> .ps DelayEventLoop :: !.ps -> .ps
DelayEventLoop ps DelayEventLoop ps
......
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