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 7:26 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Mon, 29 Jan 2018, H.J. Lu wrote:
>
>> Yes, it looks very odd. I thought the issue was with the __start/__stop
>> symbols in the shared object, not with executable. Why is -E needed?
>> I don't want to second guess. Michael, can you provide a testcase to
>> show your use case?
>
> It's exactly as I described in the thread linked by Alan. But sure,
> here's some code:
>
> % cat lib.c
> extern int __start___verbose[];
> extern int __stop___verbose[];
> extern int foo2(void);
> int foo (void)
> {
> static int my_var __attribute__((section("__verbose"))) = 5;
> if (__start___verbose == __stop___verbose // ref_regular
> || __start___verbose[0] != 5)
> return -1;
> else
> return 0;
> }
> % cat app.c
> #include <stdlib.h>
> #include <stdio.h>
> extern int foo (void);
> extern int __start___verbose[];
> extern int __stop___verbose[];
> int bar (void)
> {
> static int my_var __attribute__((section("__verbose"))) = 6;
> // no ref_regular!
> return 0;
> }
>
> int main()
> {
> if (bar () != 0)
> {
> printf("main: wrong __start___verbose\n");
> exit(2);
> }
> return 0;
> }
> % cc -g -c -o app.o app.c
> % cc -g -fPIC -c -o lib.o lib.c
> % cc -B./ -shared -o liborphan.so lib.o -Wl,-R,.
> % cc -B./ -o app app.o liborphan.so -ldl -Wl,-R,.
I tried your testcase with binutils 2.30, which doesn't have Alan's patch:
[hjl@gnu-6 orphan-4]$ cat lib.c
extern int __start___verbose[];
extern int __stop___verbose[];
extern int foo2(void);
int foo (void)
{
static int my_var __attribute__((section("__verbose"))) = 5;
if (__start___verbose == __stop___verbose // ref_regular
|| __start___verbose[0] != 5)
return -1;
else
return 0;
}
[hjl@gnu-6 orphan-4]$ cat app.c
#include <stdlib.h>
#include <stdio.h>
extern int foo (void);
extern int __start___verbose[];
extern int __stop___verbose[];
int bar (void)
{
static int my_var __attribute__((section("__verbose"))) = 6;
// no ref_regular!
return 0;
}
int main()
{
if (bar () != 0)
{
printf("main: wrong __start___verbose\n");
exit(2);
}
return 0;
}
[hjl@gnu-6 orphan-4]$ make
cc -g -c -o app.o app.c
cc -B./ -o app app.o liborphan.so -ldl -Wl,-R,.
./app
[hjl@gnu-6 orphan-4]$
It looks good to me. What am I missing?
--
H.J.