From 9fadd438cbbabcde8fe3e19644bacc044279ebdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Fri, 6 Oct 2017 17:17:26 +0200 Subject: [PATCH 2/6] build: configure: check section boundary symbols present in the test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was an idea to make apparently run-time test set to that effect, but it would make cross-building harder. So arrange the test as if it would be meant for AC_TRY_RUN, but achieve the same as with the first assertion by the means of inspecting the linked result with, possibly target-specific, nm utility. While arranging the test for AC_TRY_RUN, based on feedback by Ferenc Wágner, unify and increase usability of the run-time error signalling through assertions. Signed-off-by: Jan Pokorný --- configure.ac | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 22630ba..29bd569 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,7 @@ AC_CHECK_PROGS([DOXYGEN], [doxygen]) AM_CONDITIONAL(HAVE_DOXYGEN, test -n "${DOXYGEN}") AC_CHECK_PROGS([SPLINT], [splint]) AM_CONDITIONAL(HAVE_SPLINT, test -n "${SPLINT}") +AC_CHECK_TOOLS([NM], [eu-nm nm], [:]) ## local helper functions @@ -620,15 +621,31 @@ AC_SUBST(HAVE_SLOW_TESTS) if test "x${GCC}" = xyes; then AC_MSG_CHECKING([whether GCC supports __attribute__((section()) + ld supports orphan sections]) if test "x${ac_cv_link_attribute_section}" = x ; then - AC_TRY_LINK([#include - extern void * __start___verbose, * __stop___verbose;], - [static int my_var __attribute__((section("__verbose"))) = 5; - if (__start___verbose == __stop___verbose) assert(0); - if (my_var == 5) return 0; - else return -1; - ], - [gcc_has_attribute_section=yes], - [gcc_has_attribute_section=no]) + dnl could be turned to AC_TRY_RUN (first assertion is equivalent to + dnl the further check in action-if-true), but that would prevent + dnl cross-building + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + extern void * __start___verbose, * __stop___verbose;]], + [[static int my_var __attribute__((section("__verbose"))) = 5; + assert("non-empty data section" + && __start___verbose != __stop___verbose); + assert("no data section value loss" + && my_var == 5);]] + )], + [# alternatively something like (but requires number parsing): + # readelf -SW "conftest${ac_exeext}" \ + # | sed -n '/__verbose/s/^\s*//p' | tr -s ' ' | cut -d" " -f6 + verbose_start_addr=$(${NM} -g --portability -- "conftest${ac_exeext}" \ + | grep __start___verbose | cut -d" " -f 3) + verbose_stop_addr=$(${NM} -g --portability -- "conftest${ac_exeext}" \ + | grep __stop___verbose | cut -d" " -f 3) + test "${verbose_start_addr}" = "${verbose_stop_addr}" \ + && gcc_has_attribute_section=no \ + || gcc_has_attribute_section=yes], + [gcc_has_attribute_section=no] + ) else gcc_has_attribute_section=${ac_cv_link_attribute_section} fi -- 2.15.0