Cross compilation friendly libgpg-error
Testing, WishlistPublic

Description

For POSIX systems, lock object may be determined more easily than current gen-posix-lock-obj running on HOST system.
On BUILD system, just compile following for the HOST system:

#include <pthread.h>
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

When mtx goes into .bss section, all the content is zero.
That's the cases (for most systems, other than macOS).
This can be checked by configure when objdump/readelf is available.

gniibe created this task.Dec 9 2019, 7:58 AM
gniibe added a comment.EditedApr 6 2020, 6:41 AM

I'm testing this as an initial start:

ac_ext=c
ac_objext=o

ARCH=i686-linux-gnu
# ARCH=powerpc64le-linux-gnu

HOST_CC=$ARCH-gcc
HOST_OBJDUMP=/usr/bin/$ARCH-objdump

AWK=mawk
AWK_OPTION=
# AWK=gawk
# AWK_OPTION=--non-decimal-data

cat <<_ACEOF >conftest.$ac_ext 
#include <pthread.h>
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
_ACEOF

if $HOST_CC -c conftest.$ac_ext; then :
  ac_mtx_size=$($HOST_OBJDUMP -j .bss -t conftest.$ac_objext \
         | $AWK $AWK_OPTION '
/mtx$/ { mtx_size = int("0x" $5) }
END { print mtx_size }')
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

if test -n "$ac_mtx_size"; then
    echo "mutex size in byte is:" $ac_mtx_size
else
    echo "mutex size in byte is: unknown"
fi

This only requires cross compiler and cross objdump (or objdump for multiple architectures), it doesn't require running executable on host.

werner added a subscriber: werner.Apr 6 2020, 9:49 AM

Clever idea.

gniibe changed the task status from Open to Testing.Apr 9 2020, 9:03 AM
gniibe added a project: Testing.

Push the change to master.