Skip to content

Commit

Permalink
More work on getting merge.sh to do the right things.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 14, 2009
1 parent a1b37dc commit ddb4898
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
44 changes: 44 additions & 0 deletions misc/is32bitelf.c
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

static int check_elf(const char *fname)
{
static const unsigned char magic[4] = { 0x7F, 0x45, 0x4C, 0x46 };
size_t br = 0;
unsigned char buf[5];
FILE *f = fopen(fname, "rb");
if (f == NULL)
{
fprintf(stderr, "Can't open %s: %s\n", fname, strerror(errno));
return 1;
}

br = fread(buf, 5, 1, f);
fclose(f);

if (br != 1)
{
if (ferror(f))
fprintf(stderr, "Can't read %s: %s\n", fname, strerror(errno));
return 1;
}

if (memcmp(buf, magic, 4) != 0)
{
fprintf(stderr, "Not an ELF file\n");
return 1;
}
return buf[4] == 1 ? 0 : 1;
}

int main(int argc, const char **argv)
{
return check_elf(argv[1]);
}

// end of iself.c ...


34 changes: 24 additions & 10 deletions misc/merge.sh
Expand Up @@ -9,30 +9,44 @@ set -x
set -e

rm -rf cmake-build
mkdir cmake-build
mkdir -p cmake-build
cd cmake-build

# Special case: it's a symlink to /lib32, so it causes an endless loop.
rm -f /x86_64/lib/ld-linux.so.2
ln -s ld-2.9.so /x86_64/lib/ld-linux.so.2

cmake -DCMAKE_BUILD_TYPE=Release ../..
make -j2
gcc -o iself -s -O3 ../iself.c
gcc -o is32bitelf -s -O3 ../is32bitelf.c

#time for feh in bin boot etc lib opt sbin usr var ; do find /x86_64/$feh -type f -exec ./iself {} \; ; done |perl -w -pi -e 's/\A\x86_64\///;' |grep -v "usr/lib32/" |sort |uniq > ./binaries-64
time for feh in bin boot etc lib opt sbin usr var ; do find /x86/$feh -type f -exec ./iself {} \; ; done |perl -w -pi -e 's/\A\/x86\///;' |grep -v "usr/lib64" |sort |uniq > ./binaries-32
if [ ! -f ./binaries-32 ]; then
time for feh in bin boot etc lib opt sbin usr/bin usr/games usr/sbin usr/X11R6 usr/lib usr/local var/lib ; do find /x86/$feh -type f -exec ./iself {} \; ; done |perl -w -pi -e 's/\A\/x86\///;' |grep -v "usr/lib64" |sort |uniq > ./binaries-32
fi

for feh in `cat binaries-32` ; do
mkdir -p --mode=0755 `dirname "/x86_64/$feh"`
if [ -f "/x86_64/$feh" ]; then
FATELF=0
if [ ! -f "/x86_64/$feh" ]; then
cp -a "/x86/$feh" "/x86_64/$feh"
else
ISFATELF=0
./fatelf-validate "/x86_64/$feh" && ISFATELF=1
if [ "x$ISFATELF" = "x1" ]; then
./fatelf-replace tmp-fatelf "/x86_64/$feh" "/x86/$feh"
chmod --reference="/x86_64/$feh" tmp-fatelf
mv tmp-fatelf "/x86_64/$feh"
else
./fatelf-glue tmp-fatelf "/x86_64/$feh" "/x86/$feh"
SRCIS32BIT=0
DSTIS32BIT=0
./is32bitelf "/x86/$feh" && SRCIS32BIT=1
./is32bitelf "/x86_64/$feh" && DSTIS32BIT=1
if [ "x$SRCIS32BIT" != "x$DSTIS32BIT" ]; then
./fatelf-glue tmp-fatelf "/x86_64/$feh" "/x86/$feh"
chmod --reference="/x86_64/$feh" tmp-fatelf
mv tmp-fatelf "/x86_64/$feh"
fi
fi
chmod --reference="/x86_64/$feh" tmp-fatelf
mv tmp-fatelf "/x86_64/$feh"
else
cp -a "/x86/$feh" "/x86_64/$feh"
fi
done

Expand Down

0 comments on commit ddb4898

Please sign in to comment.