@@ -44,26 +44,35 @@ const LIBC_FILE_NAME: &str = "libc.so.6";
44
44
///
45
45
/// If `opts` has a libc, make its directory the RPATH of the binary.
46
46
/// If `opts` has a linker, make it the interpreter of the binary.
47
+ ///
48
+ /// Run `patchelf` once per option to avoid broken offsets/symbols (#297)
47
49
fn run_patchelf ( bin : & Path , opts : & Opts ) -> Result < ( ) > {
48
50
println ! (
49
51
"{}" ,
50
52
format!( "running patchelf on {}" , bin. to_string_lossy( ) . bold( ) ) . green( )
51
53
) ;
52
54
53
- let mut cmd = Command :: new ( "patchelf" ) ;
54
- cmd. arg ( bin) ;
55
55
if let Some ( lib_dir) = opts
56
56
. libc
57
57
. as_ref ( )
58
58
// Prepend "." in case `libc`'s `parent()` is an empty path.
59
59
. and_then ( |libc| Path :: new ( "." ) . join ( libc) . parent ( ) . map ( Path :: to_path_buf) )
60
60
{
61
- cmd . arg ( "--set-rpath" ) . arg ( lib_dir) ;
61
+ run_patchelf_option ( bin , "--set-rpath" , & lib_dir) ? ;
62
62
} ;
63
63
if let Some ( ld) = & opts. ld {
64
- cmd . arg ( "--set-interpreter" ) . arg ( ld) ;
64
+ run_patchelf_option ( bin , "--set-interpreter" , ld) ? ;
65
65
} ;
66
66
67
+ Ok ( ( ) )
68
+ }
69
+
70
+ /// Run `patchelf` on the binary `bin` using the option `option` with the path `argument`.
71
+ fn run_patchelf_option ( bin : & Path , option : & str , argument : & PathBuf ) -> Result < ( ) > {
72
+ let mut cmd = Command :: new ( "patchelf" ) ;
73
+ cmd. arg ( bin) ;
74
+ cmd. arg ( option) . arg ( argument) ;
75
+
67
76
let status = cmd. status ( ) . context ( PatchelfExecSnafu ) ?;
68
77
if status. success ( ) {
69
78
Ok ( ( ) )
0 commit comments