Showing posts with label elf. Show all posts
Showing posts with label elf. Show all posts

Tuesday, April 29, 2008

Boolean Difference with object files

if [ -f $OUTPUT_FILE ]; then
rm -i $OUTPUT_FILE
fi

if [ -f $OUTPUT_FILE ]; then
echo "Must remove ${OUTPUT_FILE}"
exit
fi

rm -rf ./$INPUT_LIB_DIR
mkdir $INPUT_LIB_DIR
cd $INPUT_LIB_DIR

ar x $INPUT_LIB

cd ..

rm -rf ./$SUBTRACT_LIB_DIR
mkdir $SUBTRACT_LIB_DIR
cd $SUBTRACT_LIB_DIR

ar x $SUBTRACT_LIB

cd ..

rm -rf ./$OUTPUT_DIR
mkdir $OUTPUT_DIR

cd $INPUT_LIB_DIR

for a in ./*.o
do
if [ -f ../$SUBTRACT_LIB_DIR/${a} ]; then
echo "Skipping " ${a} > /dev/null
else
echo "Including " ${a}
cp ${a} ../$OUTPUT_DIR
fi
done

cd ..

for a in ./$OUTPUT_DIR/*.o
do
ar r ./$OUTPUT_FILE $a
done
ranlib ./$OUTPUT_FILE

rm -rf ./$INPUT_LIB_DIR
rm -rf ./$SUBTRACT_LIB_DIR
rm -rf ./$OUTPUT_DIR



Note: Code Formatting

Friday, April 4, 2008

Thread Local Storage

So, I've been wondering where exactly this magic thread storage comes from. Apparently it is just a symbol type that the thread subsystem will utilize to alloc on thread creation. That is super wacky, but is exactly what I wanted to know. Now I can write my lockless lock contention detector no problem.
__thread bool awesome = TRUE;
Using Thread Local Storage
http://docs.sun.com/app/docs/doc/817-1984/6mhm7pl2a?a=view

STT_TLS in ELF files
http://blogs.sun.com/ali/entry/inside_elf_symbol_tables

This could be complemented with symbol from pointer lookup via dladdr()
http://linux.die.net/man/3/dlopen