summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-03-17 05:21:24 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-03-17 05:21:24 (EDT)
commit7a6b2c4012309b1c525f51da5908a0c7b0290dd7 (patch)
tree9575b7828aa8a9e81c6ce32f534640a244465217 /tools
parent8f8a0fe145e0302c453993bc9a92b9f3387b4aa9 (diff)
tools/shld.sh: Add a basic RTLD
Diffstat (limited to 'tools')
-rwxr-xr-xtools/shld.sh45
1 files changed, 39 insertions, 6 deletions
diff --git a/tools/shld.sh b/tools/shld.sh
index 41751d3..3117ccf 100755
--- a/tools/shld.sh
+++ b/tools/shld.sh
@@ -2,7 +2,7 @@
#
# Shell command language linker
#
-# Copyright (C) 2015 Patrick "P. J." McDermott
+# Copyright (C) 2015, 2019 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
set -u
-VERSION='0.2.0'
+VERSION='0.3.0'
die()
{
@@ -35,8 +35,9 @@ link()
local make_executable="${1}"
local interpreter="${2}"
local entry_point="${3}"
- local output="${4}"
- shift 4
+ local libs="${4}"
+ local output="${5}"
+ shift 5
local input=
# Open output file.
@@ -58,6 +59,33 @@ link()
}
EOF
+ # Write __DT_NEEDED list and basic RTLD.
+ printf "__DT_NEEDED='%s'\n" "${libs}" >&3
+ cat >&3 <<-'EOF'
+ : ${SHLD_LIBRARY_PATH:=${LIBDATADIR}}
+ for __lib in ${__DT_NEEDED}; do
+ __found=false
+ IFS=':'
+ for __el in ${SHLD_LIBRARY_PATH}; do
+ if __f="$(cat "${__el}/${__lib}" 2>/dev/null)"
+ then
+ eval "${__f}"
+ __found=true
+ break
+ fi
+ done
+ unset IFS
+ if ! ${__found}; then
+ printf "%s: error while loading shell $(: \
+ )shared libraries: %s: cannot open $(: \
+ )shell shared object file\n" \
+ "${0}" "${__lib}" >&2
+ exit 127
+ fi
+ done
+ unset __lib __el __found
+ EOF
+
# Read input files.
for input in "${@}"; do
if ! cat "${input}" >&3; then
@@ -101,6 +129,7 @@ help()
Options:
-h Display this information
-V Display linker version information
+ -l <lib> Add <lib> to the list of libraries to load at run time
-I <interp> Make an executable and use <interp> as the interpreter for your
program, instead of the default of "/bin/sh"
-e <entry> Make an executable and use <entry> as the function for beginning
@@ -124,12 +153,13 @@ EOF
main()
{
local opt=
+ local libs=''
local make_executable=false
local interpreter='/bin/sh'
local entry_point='main'
local output='out.sh'
- while getopts 'hVI:e:o:' opt; do
+ while getopts 'hVl:I:e:o:' opt; do
case "${opt}" in
'h')
help
@@ -139,6 +169,9 @@ main()
version
exit
;;
+ 'l')
+ libs="${libs}${OPTARG} "
+ ;;
'I')
interpreter="${OPTARG}"
make_executable=true
@@ -159,7 +192,7 @@ main()
exit 1
fi
- link "${make_executable}" "${interpreter}" "${entry_point}" \
+ link "${make_executable}" "${interpreter}" "${entry_point}" "${libs}" \
"${output}" "${@}"
}