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
# (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)
# use_optimizing_linker_and_gcc = is_optimizing_linker linker
| use_optimizing_linker_and_gcc
//First call the optimizing linker to generate an intermediate optimized object file which is then passed to gcc
# object_paths = [optionspathname : StrictListToList (RemoveDup object_file_names)]
# temp_file_name = "/tmp/linkerXXXXXX" +++ "\0" // +++ because modified by mkstemp
# fd = mkstemp temp_file_name
| fd== -1
= abort "mkstemp failed\n"
# r = close fd
| r== -1
= abort "close failed\n"
//Call optimized linker
# linker_args = add_options_string_to_args 0 options1 [temp_file_name:object_paths]
# (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
| not link_ok
| unlink (temp_file_name+++"\0")<>0
= (ps,link_ok)
= (ps,link_ok)
//Call gcc
# ld_args = ["-o",path,temp_file_name:add_options_string_to_args 0 options2 (StrictListToList (Append library_file_names "-lm"))]
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
# 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"
= linkGCC object_paths options2 ps
= linkOther linker object_paths ps
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
# temp_file_name = "/tmp/linkerXXXXXX" +++ "\0" // +++ because modified by mkstemp
# fd = mkstemp temp_file_name
| fd== -1
= abort "mkstemp failed\n"
# r = close fd
| r== -1
= abort "close failed\n"
//Call optimized linker
# linker_args = add_options_string_to_args 0 options1 [temp_file_name:object_paths]
# (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
| not link_ok
| unlink (temp_file_name+++"\0")<>0
= (ps,link_ok)
= (ps,link_ok)
| otherwise
//Call other/additional linker
# 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 = ["-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)
is_optimizing_linker :: !{#Char} -> Bool
is_optimizing_linker name
# len = size name
= len >= 14 && (name % (len - 14, len) == "lib/exe/linker")
//Call gcc
= linkGCC [temp_file_name] options2 ps
//Just link with gcc
linkGCC object_paths gccOptions ps
# gcc_options = add_options_string_to_args 0 gccOptions (StrictListToList (Append library_file_names "-lm"))
# ld_args = ["-o", path : object_paths ] ++ gcc_options
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
= (ps,link_ok)
//Call other/additional linker
linkOther linker object_paths 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 = ListToStrictList object_paths
, 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 = ["-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
......
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