-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from NordSecurity/LLT-5072_investigate_binary_…
…strip_strategies LLT-5072: Investigate binary strip strategies
- Loading branch information
Showing
6 changed files
with
123 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from os import path | ||
import rust_build_utils.rust_utils as rutils | ||
from rust_build_utils.rust_utils_config import GLOBAL_CONFIG | ||
|
||
|
||
def strip(project: rutils.Project, config: rutils.CargoConfig, packages=None): | ||
if config.target_os != "linux" or config.debug or packages == None: | ||
return | ||
|
||
strip_bin = GLOBAL_CONFIG["linux"]["archs"][config.arch]["strip_path"] | ||
if not path.isfile(strip_bin): | ||
# fallback to default strip | ||
strip_bin = "objcopy" | ||
|
||
dist_dir = project.get_distribution_path( | ||
config.target_os, config.arch, "", config.debug | ||
) | ||
|
||
def _create_debug_symbols(bin_path: str): | ||
create_debug_symbols_cmd = [ | ||
f"{strip_bin}", | ||
"--only-keep-debug", | ||
"--compress-debug-sections=zlib", | ||
f"{bin_path}", | ||
f"{bin_path}.debug", | ||
] | ||
rutils.run_command(create_debug_symbols_cmd) | ||
|
||
set_read_only_cmd = ["chmod", "0444", f"{bin_path}.debug"] | ||
rutils.run_command(set_read_only_cmd) | ||
|
||
def _strip_debug_symbols(bin_path: str): | ||
strip_cmd = [f"{strip_bin}", "--strip-all", f"{bin_path}"] | ||
rutils.run_command(strip_cmd) | ||
|
||
for _, bins in packages.items(): | ||
for _, bin in bins.items(): | ||
bin_path = f"{dist_dir}/{bin}" | ||
_create_debug_symbols(bin_path) | ||
_strip_debug_symbols(bin_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters