This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Define __start/__stop symbols when there is only a dynamic def
On Mon, Jan 29, 2018 at 8:50 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Mon, 29 Jan 2018, H.J. Lu wrote:
>
>> We need a run-time testcase. Can you provide a run-time testcase?
>
> Replace app.c from last mail with this, add -ldl as appropriate. Only
> works on systems that have RTLD_DEFAULT (RTLD_SELF could also be used, but
> those are are subset of the former).
>
> % cat app.c
> #define _GNU_SOURCE
> #include <stdlib.h>
> #include <stdio.h>
> #include <dlfcn.h>
>
> extern int __start___verbose[];
> extern int __stop___verbose[];
> int bar (void)
> {
> static int my_var __attribute__((section("__verbose"))) = 6;
> int *ptr;
> ptr = (int*) dlsym(RTLD_DEFAULT, "__start___verbose");
> if (!ptr || *ptr != 6)
> return -1;
> return 0;
> }
>
> int main()
> {
> if (bar () != 0)
> {
> printf("main: wrong __start___verbose\n");
> exit(2);
> }
> return 0;
> }
Just to verify. This is the correct testcase:
[hjl@gnu-6 orphan-4]$ cat app.c
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
extern int __start___verbose[];
extern int __stop___verbose[];
int bar (void)
{
static int my_var __attribute__((section("__verbose"))) = 6;
int *ptr;
ptr = (int*) dlsym(RTLD_DEFAULT, "__start___verbose");
if (!ptr || *ptr != 6)
return -1;
return 0;
}
int main()
{
if (bar () != 0)
{
printf("main: wrong __start___verbose\n");
return 2;
}
return 0;
}
[hjl@gnu-6 orphan-4]$ make
cc -g -c -o app.o app.c
cc -B./ -o app app.o -ldl -Wl,-R,.
./app
main: wrong __start___verbose
make: *** [Makefile:6: all] Error 2
[hjl@gnu-6 orphan-4]$
Thanks.
--
H.J.