Page MenuHome GnuPG

Cross compilation friendly libgpg-error
Closed, ResolvedPublic

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.

Event Timeline

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.

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

Push the change to master.

For GNU/Linux, it's done.