diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2008-10-28 17:06:54 +0200 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2008-11-02 18:59:55 +0200 |
commit | 605e314f26257ba680b8d2b06526bc928a91f3b4 (patch) | |
tree | aed09be5e646b117eccebe9fa59a899a78fbd3ce /lua_scripts | |
parent | 61080fc19c7501f0b664a516c939c31d8ab32559 (diff) |
Fixes to exec preprocessing: Processing of gcc tools requires abs.paths etc. - Fix: exec parameters are now modified only when gcc tools are called from /usr/bin (previously the path was ignored, only basename was used to identify the tools) - Enhancement/fix: This includes support for rewriting paths like /usr/bin/gcc-3.4; sb2-init writes compiler version to the config files, so that exec preprocessing can register wrappers with version number for gcc, g++ and cpp - This patch also increments SB2's configuration file version number; sb2-init must be used to register gcc's version number to the config.files
Diffstat (limited to 'lua_scripts')
-rw-r--r-- | lua_scripts/argvenvp.lua | 17 | ||||
-rw-r--r-- | lua_scripts/argvenvp_gcc.lua | 126 |
2 files changed, 90 insertions, 53 deletions
diff --git a/lua_scripts/argvenvp.lua b/lua_scripts/argvenvp.lua index 40f9fa9..3ea7284 100644 --- a/lua_scripts/argvenvp.lua +++ b/lua_scripts/argvenvp.lua @@ -25,7 +25,7 @@ end -- new_filename = "exec-this-binary-instead", -- disable_mapping = 1 -- set this to disable mappings -- } --- argvmods[rule.name] = rule +-- argvmods["/path/prefix/to/tool/"..rule.name] = rule -- -- Environment modifications are not supported yet, except for disabling -- mappings. @@ -39,7 +39,7 @@ dpkg_architecture = { name = "dpkg-architecture", remove = {"-f"} } -argvmods[dpkg_architecture.name] = dpkg_architecture +argvmods["/usr/bin/"..dpkg_architecture.name] = dpkg_architecture -- ------------------------------------ -- Exec preprocessing. @@ -52,19 +52,26 @@ argvmods[dpkg_architecture.name] = dpkg_architecture function sbox_execve_preprocess(filename, argv, envp) local new_argv = {} local new_envp = {} - local binaryname = string.match(filename, "[^/]+$") local new_filename = filename - -- print(string.format("sbox_execve_preprocess(): %s\n", filename)) + if (debug_messages_enabled) then + sb.log("debug", string.format( + "sbox_execve_preprocess(): %s\n", filename)) + end new_envp = envp - local am = argvmods[binaryname] + local am = argvmods[filename] if (am and not am.remove) then am.remove = {} end if (am and not am.add_head) then am.add_head = {} end if (am and not am.add_tail) then am.add_tail = {} end if (am ~= nil) then + if (debug_messages_enabled) then + sb.log("debug", string.format( + "argvmods[%s] found\n", filename)) + end + -- head additions for i = 1, table.maxn(am.add_head) do table.insert(new_argv, am.add_head[i]) diff --git a/lua_scripts/argvenvp_gcc.lua b/lua_scripts/argvenvp_gcc.lua index e8e754a..160d527 100644 --- a/lua_scripts/argvenvp_gcc.lua +++ b/lua_scripts/argvenvp_gcc.lua @@ -5,63 +5,93 @@ -- argv/envp manglings gcc_compilers = { -"cc", -"gcc", -"c++", -"g++", -"cpp", -"f77", -"g77" + "cc", + "gcc", + "c++", + "g++", + "cpp", + "f77", + "g77" +} + +-- names, where sbox_cross_gcc_shortversion may be embedded to the name +-- (e.g. gcc-3.4, g++-3.4) +gcc_compilers_with_version = { + "gcc", + "g++", + "cpp" } gcc_linkers = { -"ld" + "ld" } gcc_tools = { -"addr2line", -"ar", -"as", -"c++filt", -"gccbug", -"gcov", -"nm", -"objcopy", -"objdump", -"ranlib", -"readelf", -"size", -"strings", -"strip" + "addr2line", + "ar", + "as", + "c++filt", + "gccbug", + "gcov", + "nm", + "objcopy", + "objdump", + "ranlib", + "readelf", + "size", + "strings", + "strip" } +function register_gcc_component_path(tmp) + -- currently all gcc tools (that we are going to process) live in /usr/bin + local full_path = "/usr/bin/" .. tmp.name + + argvmods[full_path] = tmp +end + +function gcc_compiler_arg_mods(tmp) + tmp.add_tail = {} + tmp.remove = {} + if (sbox_cross_gcc_specs_file and sbox_cross_gcc_specs_file ~= "") then + table.insert(tmp.add_tail, "-specs="..sbox_cross_gcc_specs_file) + end + if (sbox_extra_cross_compiler_args and sbox_extra_cross_compiler_args ~= "") then + for gcc_extra in string.gmatch(sbox_extra_cross_compiler_args, "[^ ]+") do + table.insert(tmp.add_tail, gcc_extra) + end + end + if (sbox_extra_cross_compiler_stdinc and sbox_extra_cross_compiler_stdinc ~= "") then + for gcc_stdinc in string.gmatch(sbox_extra_cross_compiler_stdinc, "[^ ]+") do + table.insert(tmp.add_tail, gcc_stdinc) + end + end + if (sbox_block_cross_compiler_args and sbox_block_cross_compiler_args ~= "") then + for gcc_block in string.gmatch(sbox_block_cross_compiler_args, "[^ ]+") do + table.insert(tmp.remove, gcc_block) + end + end +end + -- The trick with ":" .. is to have a non-prefixed gcc call caught here for prefix in string.gmatch(":" .. sbox_cross_gcc_prefix_list, "[^:]*") do + + -- Compiler tools without version suffix for i = 1, table.maxn(gcc_compilers) do local tmp = {} tmp.name = prefix .. gcc_compilers[i] tmp.new_filename = sbox_cross_gcc_dir .. "/" .. sbox_cross_gcc_subst_prefix .. gcc_compilers[i] - tmp.add_tail = {} - tmp.remove = {} - if (sbox_cross_gcc_specs_file and sbox_cross_gcc_specs_file ~= "") then - table.insert(tmp.add_tail, "-specs="..sbox_cross_gcc_specs_file) - end - if (sbox_extra_cross_compiler_args and sbox_extra_cross_compiler_args ~= "") then - for gcc_extra in string.gmatch(sbox_extra_cross_compiler_args, "[^ ]+") do - table.insert(tmp.add_tail, gcc_extra) - end - end - if (sbox_extra_cross_compiler_stdinc and sbox_extra_cross_compiler_stdinc ~= "") then - for gcc_stdinc in string.gmatch(sbox_extra_cross_compiler_stdinc, "[^ ]+") do - table.insert(tmp.add_tail, gcc_stdinc) - end - end - if (sbox_block_cross_compiler_args and sbox_block_cross_compiler_args ~= "") then - for gcc_block in string.gmatch(sbox_block_cross_compiler_args, "[^ ]+") do - table.insert(tmp.remove, gcc_block) - end - end - argvmods[tmp.name] = tmp + gcc_compiler_arg_mods(tmp) + register_gcc_component_path(tmp) + end + -- Compiler tools with version suffix + for i = 1, table.maxn(gcc_compilers_with_version) do + local tmp = {} + tmp.name = prefix .. gcc_compilers_with_version[i] .. "-" .. + sbox_cross_gcc_shortversion + tmp.new_filename = sbox_cross_gcc_dir .. "/" .. sbox_cross_gcc_subst_prefix .. gcc_compilers_with_version[i] + gcc_compiler_arg_mods(tmp) + register_gcc_component_path(tmp) end -- just map the filename for linkers and tools @@ -81,13 +111,13 @@ for prefix in string.gmatch(":" .. sbox_cross_gcc_prefix_list, "[^:]*") do table.insert(tmp.remove, ld_block) end end - argvmods[tmp.name] = tmp + register_gcc_component_path(tmp) end for i = 1, table.maxn(gcc_tools) do local tmp = {} tmp.name = prefix .. gcc_tools[i] tmp.new_filename = sbox_cross_gcc_dir .. "/" .. sbox_cross_gcc_subst_prefix .. gcc_tools[i] - argvmods[tmp.name] = tmp + register_gcc_component_path(tmp) end end @@ -111,7 +141,7 @@ for prefix in string.gmatch(sbox_host_gcc_prefix_list, "[^:]+") do table.insert(tmp.remove, gcc_block) end end - argvmods[tmp.name] = tmp + register_gcc_component_path(tmp) end -- just map the filename for linkers and tools @@ -120,14 +150,14 @@ for prefix in string.gmatch(sbox_host_gcc_prefix_list, "[^:]+") do tmp.name = prefix .. gcc_linkers[i] tmp.new_filename = sbox_host_gcc_dir .. "/" .. sbox_host_gcc_subst_prefix .. gcc_linkers[i] tmp.disable_mapping = 1 - argvmods[tmp.name] = tmp + register_gcc_component_path(tmp) end for i = 1, table.maxn(gcc_tools) do local tmp = {} tmp.name = prefix .. gcc_tools[i] tmp.new_filename = sbox_host_gcc_dir .. "/" .. sbox_host_gcc_subst_prefix .. gcc_tools[i] tmp.disable_mapping = 1 - argvmods[tmp.name] = tmp + register_gcc_component_path(tmp) end end |