This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Weak hidden undefined symbol loses hidden visiblity with GCC 4.7.2
- From: Henrik Wallin <henrikwallin72 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Cc: Martin Ãnsal <martinunsal at gmail dot com>
- Date: Thu, 8 May 2014 09:31:01 +0200
- Subject: Re: Weak hidden undefined symbol loses hidden visiblity with GCC 4.7.2
- Authentication-results: sourceware.org; auth=none
Hi,
(Reply to: http://gcc.gnu.org/ml/gcc-help/2014-05/msg00005.html)
I think I see the same problems, but for powerpc.
The problems is seen with gcc 4.8.1. It works good with gcc 4.6.3.
The original lttng problem can not be seen with an x86 system (not
sure why yet), but the code snippet below seems to trigger for x86 as
well.
I've tried to construct a shorted down variant of what I think is happening.
Hopefully it matches what is happening in the real lttng case.
I hope it can shed some light to this issue.
Is it gcc / binutils problem? Or wrong use of attributes from lttng's side?
Attached is a bug.c file. See the comments how to build.
Removing the "weak" attribute will make things work for all tested toolchains.
I've seen some indications that using weak+hidden might be considered
"bad practice"
(e.g. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32219)
--
/ Henrik
/*
* gcc -DSO_1 -shared -fPIC -m64 bug.c -o libbug_1.so
* gcc -DSO_2 -shared -fPIC -m64 bug.c -o libbug_2.so
* gcc -DMAIN -m64 bug.c -o bug -L. -lbug_1 -lbug_2
* LD_LIBRARY_PATH=. ./bug
*
* Some outputs for me:
* (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
* (gcc: 4.6.3): OK
* (Wind River Linux Sourcery CodeBench 4.8-28) 4.8.1:
* (gcc: 4.8.1): FAIL
*/
#ifndef MAIN
#ifdef SO_1
#define VAR_NAME SO_1_var
#define VAR_VALUE 42
#endif
#ifdef SO_2
#define VAR_NAME SO_2_var
#define VAR_VALUE 8911
#endif
extern int const __start___my_section[] __attribute__((weak, visibility("hidden")));
static void __attribute__((constructor)) my_constructor(void);
int VAR_NAME = 0;
static void my_constructor(void)
{
VAR_NAME = __start___my_section[0];
}
static int my_var __attribute__((used, section("__my_section"))) = VAR_VALUE;
#else /* MAIN */
extern int SO_1_var;
extern int SO_2_var;
#include <stdio.h>
int main(void)
{
int ok = SO_1_var == 42 && SO_2_var == 8911;
printf("(gcc: " __VERSION__ "): %s\n", ok ? "OK" : "FAIL");
return !ok;
}
#endif