Define __start/__stop symbols when there is only a dynamic def

H.J. Lu hjl.tools@gmail.com
Mon Jan 29 22:58:00 GMT 2018


On Mon, Jan 29, 2018 at 10:28 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Mon, 29 Jan 2018, H.J. Lu wrote:
>
>> > % 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]$
>
> Yes, that's it.  (the associated lib.c needs to have a regular ref symbol
> to __start___symbol and that lib needs to have something else than "6" in
> its __verbose section, in order to test the exact situation of pacemaker).
> With the patch from Alan ./app will have __start___verbose in its symbol
> table, but not yet in the dynamic symbol table.  So with only Alans patch
> -E would be necessary.  With the addition of the
> bfd_elf_link_record_dynamic_symbol() call to bfd_elf_define_start_stop the
> above testcase will start working as is even without -E.

I don't think Alan's patch nor yours are correct.   Here is mine with your
testcase.   OK for master?

Thanks.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ELF-Always-make-__start-and-__stop-symbols-dynamic.patch
Type: text/x-patch
Size: 4610 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180129/ca8f1f63/attachment.bin>


More information about the Binutils mailing list