This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: binutils 2.20.1 on irix 6.5.22 _rld_new_interface question


Those are the GCC start and end files though.  The crt1.o that I mentioned
is part of IRIX (/usr/lib*/crt1.o, IIRC) and should get linked into every
executable.  That's the file that I thought mentioned __rld_obj_head.

Ah, you are correct:

bash-4.1$ /usr/bin/nm crt1.o | grep __rld_obj
[17]    |        16|       4|OBJT |GLOB |DEFAULT  |COMMON |__rld_obj_head

I mistakenly assumed that the gcc crt* files replaced the system crt* files for GCC objects.

My _guess_ is that is what is happening in the current linker code (and
why).  libc.so.1 has an undefined reference to _rld_new_interface, this
prevented *all* code from linking when using gnu-ld, so a patch was put in
that basically ignored the libc.so.1 reference, pretend it doesn't exist.

However in an object file that DOES refernce it, you have to list it (as
undefined) in the symbol table; ignoring it doesn't work (you have to
create the "hook" in the object table for the runtime linker to add a
symbol for; I *think* this is what __rld_obj_head is doing (but for a
"data" reference instead of a "text" reference).

But my point was that your use of _rld_new_interface seems to be coming from a regular relocatable object (.o) -- namely dso_dlfcn.o -- rather than a DSO (.so) input like libc.so.1. The code in question is:

 if (SGI_COMPAT (abfd)
     && (abfd->flags & DYNAMIC) != 0
     && strcmp (*namep, "_rld_new_interface") == 0)
   {
     /* Skip IRIX5 rld entry name.  */
     *namep = NULL;
     return TRUE;
   }

and the (abfd->flags & DYNAMIC) != 0 check is supposed to restrict this
code to DSO inputs.  It shouldn't trigger for regular .o files like
dso_dlfcn.o.  So my guess was that the reference from dso_dlfcn.o gets
past this check, but there's some other failure that stops the relocations
against the symbol from being processed correctly.  I suppose something like:

 if (SGI_COMPAT (abfd)
     && strcmp (*namep, "_rld_new_interface") == 0)
   printf ("Keeping _rld_new_interface from %s\n", abfd->filename);

after the code above would verify this.

Yes, most certainly, that's what I meant to indicate in my earlier email, in the course of my debugging, I did exactly this, and it *definitely* prints out when ld hits that portion of the code



Perhaps the problem is that the check above is also skipping the definition of the symbol (in libdl.so, or whatever), and thus the linker has nothing to resolve the relocations against. Try adding && sym->st_shndx == SHN_UNDEF

to the condition, i.e.:

 if (SGI_COMPAT (abfd)
     && (abfd->flags & DYNAMIC) != 0
     && sym->st_shndx == SHN_UNDEF
     && strcmp (*namep, "_rld_new_interface") == 0)
   {
     /* Skip IRIX5 rld entry name.  */
     *namep = NULL;
     return TRUE;
   }

Right, that is exactly it... only that symbol *isn't* defined anywhere (at least not that's passed to the linker, it exists internally in /lib32/rld and nowhere else:

bash-4.1$ /usr/bin/nm /lib32/libc.so.1 | grep _rld_new_interface
[6243]  |         0|       0|FUNC |GLOB |DEFAULT  |UNDEF  |_rld_new_interface

bash-4.1$ /usr/bin/nm /usr/lib32/libdl.so | grep _rld_new_interface
(nothing)

bash-4.1$ /usr/bin/nm /lib32/rld | grep _rld_new_interface
[25]    | 263621536|    1264|FUNC |GLOB |DEFAULT  |3      |_rld_new_interface_body
[28]    | 263587164|     104|FUNC |GLOB |DEFAULT  |3      |_rld_new_interface

So (I think) what needs to happen is to create some bogus placeholder for the linker to THINK it has to resolve against, and just go. When the program is run "rld" knows where the symbols are, since it has them itself (which is why --warn-unresolved-symbols lets it work)

Symbols from /lib32/libc.so.1: >>
[Index] Value Size Type Bind Other Shndx Name

[6243] | 0| 0|FUNC |GLOB |DEFAULT |UNDEF |_rld_new_interface


dso_dlfcn (when linked with Irix ld)


[46] | 268438512| 0|FUNC |GLOB |DEFAULT |UNDEF |_rld_new_interface

dso_dlfcn.o (when compiled with Irix cc)

[6] | 0| 0|FUNC |GLOB |DEFAULT |UNDEF |_rld_new_interface


dso_dlfcn.o (when compiled with gcc)


[11] | 0| 0|OBJT |GLOB |DEFAULT |UNDEF |_rld_new_interface

Could you also show the relocations against _rld_new_interface in dso_dlfcn.o? Like you say, the OBJT thing is a bit odd...

Not sure what you are asking there; isn't that what I provided with the NM dumps? The OBJT thing is odd, however I also had it call 'puts' so I could see what a function that it does know about looks like, and it looks the same (and it links and runs), so I am not overly concerned.

The output above just shows the symbol table entry for _rld_new_interface. If you're using readelf, you can get the relocations using:

readelf --wide --relocs dso_dlfcn.o

(There's a way of doing it with IRIX elfdump too, if you prefer that,
but I can't remember the syntax now.)  I was just curious what
relocations (R_MIPS_*) you had against _rld_new_interface.

Ok, for reference here is mt dso_dlfcn.c:


#include <stdio.h>
#include <dlfcn.h>
#include <rld_interface.h>
#ifndef _RLD_INTERFACE_DLFCN_H_DLADDR
#define _RLD_INTERFACE_DLFCN_H_DLADDR
typedef struct Dl_info {
    const char * dli_fname;
    void       * dli_fbase;
    const char * dli_sname;
    void       * dli_saddr;
    int          dli_version;
    int          dli_reserved1;
    long         dli_reserved[4];
} Dl_info;
#else
typedef struct Dl_info Dl_info;
#endif
#define _RLD_DLADDR             14

static int dladdr(void *, Dl_info *);

int main(int argc, char **argv)
{
        Dl_info data;

        dladdr(main, &data);
        puts("hello world\n");
        return 0;
}

static int dladdr(void *address, Dl_info *dl)
{
        void *v;
        v = _rld_new_interface(_RLD_DLADDR,address,dl);
        return (int)v;
}


bash-4.1$ gcc -c -o dso_dlfcn.o dso_dlfcn.c bash-4.1$ readelf --wide --relocs dso_dlfcn.o

Relocation section '.rela.text' at offset 0x588 contains 22 entries:
Offset Info Type Sym. Value Symbol's Name + Addend
00000014 00000807 R_MIPS_GPREL16 00000000 main + 0
00000014 00000018 R_MIPS_SUB 00000000
00000014 00000005 R_MIPS_HI16 00000000
0000001c 00000807 R_MIPS_GPREL16 00000000 main + 0
0000001c 00000018 R_MIPS_SUB 00000000
0000001c 00000006 R_MIPS_LO16 00000000
00000028 00000813 R_MIPS_GOT_DISP 00000000 main + 0
00000030 00000114 R_MIPS_GOT_PAGE 00000000 .text + 7c
00000034 00000115 R_MIPS_GOT_OFST 00000000 .text + 7c
00000044 00000514 R_MIPS_GOT_PAGE 00000000 .rodata + 80
00000048 00000515 R_MIPS_GOT_OFST 00000000 .rodata + 80
0000004c 00000a0b R_MIPS_CALL16 00000000 puts + 0
00000090 00000107 R_MIPS_GPREL16 00000000 .text + 7c
00000090 00000018 R_MIPS_SUB 00000000
00000090 00000005 R_MIPS_HI16 00000000
00000098 00000107 R_MIPS_GPREL16 00000000 .text + 7c
00000098 00000018 R_MIPS_SUB 00000000
00000098 00000006 R_MIPS_LO16 00000000
000000b0 00000b0b R_MIPS_CALL16 00000000 _rld_new_interface + 0
0000003c 00000925 R_MIPS_JALR 0000007c dladdr + 0
00000054 00000a25 R_MIPS_JALR 00000000 puts + 0
000000b8 00000b25 R_MIPS_JALR 00000000 _rld_new_interface + 0


Relocation section '.rela.debug_frame' at offset 0x690 contains 4 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name + Addend
00000018  00000402 R_MIPS_32              00000000   .debug_frame + 0
0000001c  00000102 R_MIPS_32              00000000   .text + 0
00000038  00000402 R_MIPS_32              00000000   .debug_frame + 0
0000003c  00000102 R_MIPS_32              00000000   .text + 7c

bash-4.1$ cc -c -o dso_dlfcn.o dso_dlfcn.c

Relocation section '.rel.MIPS.events.text' at offset 0x4d0 contains 4 entries:
Offset Info Type Sym. Value Symbol's Name
00000001 00000120 R_MIPS_SCN_DISP 00000000 .text
0000000a 00000420 R_MIPS_SCN_DISP 00000070 dladdr
0000000e 0000050b R_MIPS_CALL16 00000000 puts
00000018 0000060b R_MIPS_CALL16 00000000 _rld_new_interface


Relocation section '.rela.text' at offset 0x4f0 contains 14 entries:
Offset Info Type Sym. Value Symbol's Name + Addend
0000000c 00000307 R_MIPS_GPREL16 00000000 main + 0
0000000c 00000018 R_MIPS_SUB 00000000
0000000c 00000005 R_MIPS_HI16 00000000
00000010 00000307 R_MIPS_GPREL16 00000000 main + 0
00000010 00000018 R_MIPS_SUB 00000000
00000010 00000006 R_MIPS_LO16 00000000
00000020 00000313 R_MIPS_GOT_DISP 00000000 main + 0
00000028 00000414 R_MIPS_GOT_PAGE 00000070 dladdr + 0
0000002c 00000415 R_MIPS_GOT_OFST 00000070 dladdr + 0
00000030 00000425 R_MIPS_JALR 00000070 dladdr + 0
00000038 00000214 R_MIPS_GOT_PAGE 00000000 .rodata + 0
0000003c 00000215 R_MIPS_GOT_OFST 00000000 .rodata + 0
00000044 00000525 R_MIPS_JALR 00000000 puts + 0
00000090 00000625 R_MIPS_JALR 00000000 _rld_new_interface + 0


Relocation section '.rel.text' at offset 0x598 contains 2 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000040  0000050b R_MIPS_CALL16          00000000   puts
0000008c  0000060b R_MIPS_CALL16          00000000   _rld_new_interface

Relocation section '.rel.debug_info' at offset 0x798 contains 8 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000006  00000902 R_MIPS_32              00000000   .debug_abbrev
0000001b  00000802 R_MIPS_32              00000000   .debug_line
0000002e  00000102 R_MIPS_32              00000000   .text
00000032  00000102 R_MIPS_32              00000000   .text
00000036  00000a02 R_MIPS_32              00000000   .debug_frame
00000049  00000102 R_MIPS_32              00000000   .text
0000004d  00000102 R_MIPS_32              00000000   .text
00000051  00000a02 R_MIPS_32              00000000   .debug_frame

Relocation section '.rel.debug_line' at offset 0x7d8 contains 1 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
0000003b  00000102 R_MIPS_32              00000000   .text

Relocation section '.rel.debug_frame' at offset 0x7e0 contains 4 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000018  00000a02 R_MIPS_32              00000000   .debug_frame
0000001c  00000102 R_MIPS_32              00000000   .text
00000040  00000a02 R_MIPS_32              00000000   .debug_frame
00000044  00000102 R_MIPS_32              00000000   .text

Relocation section '.rel.debug_aranges' at offset 0x800 contains 2 entries:
Offset Info Type Sym. Value Symbol's Name
00000006 00000702 R_MIPS_32 00000000 .debug_info
00000010 00000102 R_MIPS_32 00000000 .text


Relocation section '.rel.debug_pubnames' at offset 0x810 contains 1 entries:
Offset Info Type Sym. Value Symbol's Name
00000006 00000702 R_MIPS_32 00000000 .debug_info


Relocation section '.rel.debug_funcnames' at offset 0x818 contains 1 entries:
Offset Info Type Sym. Value Symbol's Name
00000006 00000702 R_MIPS_32 00000000 .debug_info


I hope that clears things up?

--
David E. Cross


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]