Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
63cb2f34
Verified
Commit
63cb2f34
authored
5 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
ld.so: Add auxv support, get ld_library_path from env
parent
084b69b3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ld_so/start.rs
+67
-5
67 additions, 5 deletions
src/ld_so/start.rs
with
67 additions
and
5 deletions
src/ld_so/start.rs
+
67
−
5
View file @
63cb2f34
...
@@ -20,19 +20,77 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
...
@@ -20,19 +20,77 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
loop
{}
loop
{}
}
}
// Some variables that will be overridden by environment and auxiliary vectors
let
mut
library_path
=
"/lib"
;
let
mut
page_size
=
4096
;
// Pop the first argument (path to ld_so), and get the path of the program
// Pop the first argument (path to ld_so), and get the path of the program
// TODO: Also retrieve LD_LIBRARY_PATH this way
let
path_c
=
unsafe
{
let
path_c
=
unsafe
{
let
mut
argv
=
&
mut
sp
.argv0
as
*
mut
*
const
c_char
;
let
mut
argv
=
&
mut
sp
.argv0
as
*
mut
*
const
c_char
as
*
mut
usize
;
// Move arguments
loop
{
loop
{
let
next_argv
=
argv
.add
(
1
);
let
next_argv
=
argv
.add
(
1
);
let
arg
=
*
next_argv
;
let
arg
=
*
next_argv
;
*
argv
=
arg
;
*
argv
=
arg
;
argv
=
next_argv
;
argv
=
next_argv
;
if
arg
.is_null
()
{
if
arg
==
0
{
break
;
}
if
let
Ok
(
arg_str
)
=
CStr
::
from_ptr
(
arg
as
*
const
c_char
)
.to_str
()
{
println!
(
" arg: '{}'"
,
arg_str
);
}
}
// Move environment
loop
{
let
next_argv
=
argv
.add
(
1
);
let
arg
=
*
next_argv
;
*
argv
=
arg
;
argv
=
next_argv
;
if
arg
==
0
{
break
;
}
if
let
Ok
(
arg_str
)
=
CStr
::
from_ptr
(
arg
as
*
const
c_char
)
.to_str
()
{
println!
(
" env: '{}'"
,
arg_str
);
let
mut
parts
=
arg_str
.splitn
(
2
,
'='
);
if
let
Some
(
key
)
=
parts
.next
()
{
if
let
Some
(
value
)
=
parts
.next
()
{
match
key
{
"LD_LIBRARY_PATH"
=>
library_path
=
value
,
_
=>
()
}
}
}
}
}
// Move auxiliary vectors
loop
{
let
next_argv
=
argv
.add
(
1
);
let
kind
=
*
next_argv
;
*
argv
=
kind
;
argv
=
next_argv
;
let
next_argv
=
argv
.add
(
1
);
let
value
=
*
next_argv
;
*
argv
=
value
;
argv
=
next_argv
;
if
kind
==
0
{
break
;
break
;
}
}
println!
(
" aux: {}={:#x}"
,
kind
,
value
);
match
kind
{
6
=>
page_size
=
value
,
_
=>
(),
}
}
}
sp
.argc
-=
1
;
sp
.argc
-=
1
;
CStr
::
from_ptr
(
sp
.argv0
)
CStr
::
from_ptr
(
sp
.argv0
)
...
@@ -47,7 +105,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
...
@@ -47,7 +105,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
}
}
};
};
let
mut
linker
=
Linker
::
new
(
"/usr/local/lib:/lib/x86_64-linux-gnu"
);
let
mut
linker
=
Linker
::
new
(
library_path
);
match
linker
.load
(
&
path
,
&
path
)
{
match
linker
.load
(
&
path
,
&
path
)
{
Ok
(())
=>
(),
Ok
(())
=>
(),
Err
(
err
)
=>
{
Err
(
err
)
=>
{
...
@@ -58,7 +116,11 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
...
@@ -58,7 +116,11 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
}
}
match
linker
.link
(
&
path
)
{
match
linker
.link
(
&
path
)
{
Ok
(
entry
)
=>
entry
,
Ok
(
entry
)
=>
{
eprintln!
(
"ld.so: entry '{}': {:#x}"
,
path
,
entry
);
//unistd::_exit(0);
entry
},
Err
(
err
)
=>
{
Err
(
err
)
=>
{
eprintln!
(
"ld.so: failed to link '{}': {}"
,
path
,
err
);
eprintln!
(
"ld.so: failed to link '{}': {}"
,
path
,
err
);
unistd
::
_exit
(
1
);
unistd
::
_exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment