summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Sindholt <opensource@zhasha.com>2017-12-13 15:56:18 +0100
committerJoakim Sindholt <opensource@zhasha.com>2017-12-13 15:56:18 +0100
commit5660055f6c9bf720d79836d5760ab759a1d6f3f8 (patch)
treeab1343825f48b4445f8ba9a96fbcdb8c994350ce
parentd8f2ffa150ce280acea9e96fe9f896563d7b9abf (diff)
p9l: inline nuke-pt_interp perl script
-rw-r--r--bin/nuke-pt_interp.pl33
-rw-r--r--bin/p9l.sh39
2 files changed, 38 insertions, 34 deletions
diff --git a/bin/nuke-pt_interp.pl b/bin/nuke-pt_interp.pl
deleted file mode 100644
index be5336c..0000000
--- a/bin/nuke-pt_interp.pl
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/perl
-use strict;
-
-my $fname = $ARGV[0];
-open(F,"+<$fname") or die "Couldn't open $fname for reading+writing";
-
-my $buf;
-read(F, $buf, 6);
-my ($width, $endian) = unpack("x4CC", $buf);
-if (($width != 1 && $width != 2) ||
- ($endian != 1 && $endian != 2)) { die "Invalid EI_CLASS or EI_DATA"; }
-
-my $offset;
-if ($width == 1) {
- seek(F, 0x2A, 0);
- $offset = 0x34;
-} else {
- seek(F, 0x36, 0);
- $offset = 0x40;
-}
-
-read(F, $buf, 4);
-my ($phentsize, $phnum) = unpack($endian == 1 ? "vv" : "nn", $buf);
-
-for (my $i = 0; $i < $phnum; $i++) {
- seek(F, $offset + $phentsize * $i, 0);
- read(F, $buf, 4);
- if (unpack($endian == 1 ? "V" : "N", $buf) == 3) {
- seek(F, -4, 1);
- print F pack("N", 0);
- }
-}
-close F;
diff --git a/bin/p9l.sh b/bin/p9l.sh
index 2f04f98..6730ec3 100644
--- a/bin/p9l.sh
+++ b/bin/p9l.sh
@@ -162,6 +162,43 @@ ld.gold \
"${CRTSTART[@]}" '-(' "${FARGS[@]}" "${LIBS[@]}" '-)' "${CRTEND[@]}" ||
exit 1
-perl -- "$DIR/nuke-pt_interp.pl" "$OUTPUT_NAME" || exit 1
+if ! perl -e 'use strict;
+my $fname = $ARGV[1];
+my $o = $ARGV[0];
+open(F,"+<$fname") or die "$o: $fname: $!";
+
+my $buf;
+read(F, $buf, 6) or die "$o: $fname: $!";
+my ($width, $endian) = unpack("x4CC", $buf);
+if (($width != 1 && $width != 2) ||
+ ($endian != 1 && $endian != 2)) {
+ die "$o: $fname: invalid EI_CLASS or EI_DATA";
+}
+
+my $offset;
+if ($width == 1) {
+ seek(F, 0x2A, 0) or die "$o: $fname: $!";
+ $offset = 0x34;
+} else {
+ seek(F, 0x36, 0) or die "$o: $fname: $!";
+ $offset = 0x40;
+}
+
+read(F, $buf, 4) or die "$o: $fname: $!";
+my ($phentsize, $phnum) = unpack($endian == 1 ? "vv" : "nn", $buf);
+
+for (my $i = 0; $i < $phnum; $i++) {
+ seek(F, $offset + $phentsize * $i, 0) or die "$o: $fname: $!";
+ read(F, $buf, 4) or die "$o: $fname: $!";
+ if (unpack($endian == 1 ? "V" : "N", $buf) == 3) {
+ seek(F, -4, 1) or die "$o: $fname: $!";
+ print F pack("N", 0) or die "$o: $fname: $!";
+ }
+}
+close F;' -- "$0" "$OUTPUT_NAME"
+then
+ rm -f "$OUTPUT_NAME"
+ exit 1
+fi
objcopy -R .interp "$OUTPUT_NAME" &>/dev/null
exit 0