From 1171e7042fbcedb95eecda2856275fc2a119b212 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 7 Apr 2012 22:12:41 -0700 Subject: Fixes to get configure ccname=g++ working on OSX Lion. * Makefile (conftest.syms): Use -n flag in nm so that the output is not alphabetically sorted, but numerically. We need this to get the symbols ordered by increasing offset. * configure (read_syms): New function. Factors out logic used in two places for reading the output of nm. On OSX Lion, it looks like we do not get symbol sizes but offsets only, when compiling with g++. The symbols are in an S section. When compiling with gcc, we get a common C section with symbol sizes. So the hack is to use the deltas between offsets to get the sizes. The objects had to be re-ordered in decreasing rank so alignment doesn't create padding that will get counted as the size. Interleaved dummy objects of type char should also work. --- ChangeLog | 18 +++++++++++++ Makefile | 2 +- configure | 93 ++++++++++++++++++++++++++++++++++++++------------------------- 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ee07d65..abedc1ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2012-04-07 Kaz Kylheku + + Fixes to get configure ccname=g++ working on OSX Lion. + + * Makefile (conftest.syms): Use -n flag in nm so that the output + is not alphabetically sorted, but numerically. We need this + to get the symbols ordered by increasing offset. + + * configure (read_syms): New function. Factors out logic used + in two places for reading the output of nm. On OSX Lion, it looks + like we do not get symbol sizes but offsets only, when compiling + with g++. The symbols are in an S section. When compiling with + gcc, we get a common C section with symbol sizes. + So the hack is to use the deltas between offsets to get the sizes. + The objects had to be re-ordered in decreasing rank so alignment + doesn't create padding that will get counted as the size. + Interleaved dummy objects of type char should also work. + 2012-04-07 Kaz Kylheku * configure: Print done and terminate line after checking for diff --git a/Makefile b/Makefile index 19fabd4b..f784b7e0 100644 --- a/Makefile +++ b/Makefile @@ -181,7 +181,7 @@ conftest2: conftest1.c conftest2.c $(CC) $(CFLAGS) -o $@ $^ conftest.syms: conftest.o - $(NM) -t o -P $^ > $@ + $(NM) -n -t o -P $^ > $@ .PHONY: conftest.yacc conftest.yacc: diff --git a/configure b/configure index ebd02aec..46667045 100755 --- a/configure +++ b/configure @@ -711,19 +711,61 @@ fi printf "Checking what C integer type can hold a pointer ... " +read_syms() +{ + print_into_config=${1-} + deferred_offset= + + while read symbol type offset size ; do + size=$(( 0$size + 0 )) + offset=$(( 0$offset + 0 )) + symbol=${symbol#_} + case "$type" in + C ) + size=$(( offset + 0 )) + ;; + S ) + if [ -n "$deferred_offset" ] ; then + size=$(( offset - deferred_offset )) + case "$deferred_sym" in + SIZEOF* ) + eval $(printf "%s=%d\n" "$deferred_sym" "$size") + if [ -n "$print_into_config" ] ; then + printf "#define %s %s\n" "$deferred_sym" "$size" >> config.h + fi + ;; + esac + fi + deferred_sym=$symbol + deferred_offset=$offset + continue + ;; + esac + case "$symbol" in + SIZEOF* ) + eval $(printf "%s=%d\n" "$symbol" "$size") + if [ -n "$print_into_config" ] ; then + printf "#define %s %s\n" "$symbol" "$size" >> config.h + fi + ;; + esac + done < conftest.syms +} + if [ -z "$intptr" ] ; then cat > conftest.c <> config.h - ;; - esac - done < conftest.syms + read_syms y rm -f conftest.syms conftest.o @@ -823,7 +853,8 @@ printf "Conservatively guessing the alignment of wide literals ... " if [ -z "$lit_align" ] ; then cat > conftest.c < -char sizeof_wchar_t[sizeof (wchar_t)]; +char SIZEOF_WCHAR_T[sizeof (wchar_t)]; +char DUMMY; ! rm -f conftest.o conftest.syms @@ -835,29 +866,19 @@ char sizeof_wchar_t[sizeof (wchar_t)]; exit 1 fi - sizeof_wchar_t=0 + SIZEOF_WCHAR_T=0 + deferred_offset= - while read symbol type offset size ; do - size=$(( 0$size + 0 )) - symbol=${symbol#_} - if [ "$type" = "C" ] ; then - size=$(( 0$offset + 0 )) - fi - case "$symbol" in - sizeof* ) - eval $(printf "%s=%d\n" "$symbol" "$size") - ;; - esac - done < conftest.syms + read_syms rm -f conftest.syms conftest.o - if [ $sizeof_wchar_t -eq 0 ] ; then + if [ $SIZEOF_WCHAR_T -eq 0 ] ; then printf "failed\n" exit 1 fi - lit_align=$sizeof_wchar_t + lit_align=$SIZEOF_WCHAR_T fi printf "%d\n" "$lit_align" -- cgit v1.2.3