Skip to contentSkip to conversation

Prelink for mips (Re: MIPS broken in 2.3)

DISCUSSION H . J . Lu 2 participants 4 messages Dec 17, 2001 – Jan 8, 2002 4 messages not in the archive MIPS

lore
Share & tools
lore

H . J . Lu

author
#4 lore raw
In reply to a message not in the archive
Quoted 2 lines · Jakub Jelinek

instead (well, best would be if somebody ported prelink to mips; I'll try to answer any questions and help).

Do you have some documentations how prelink works?

Quoted 3 lines

I skipped mips because it is way too different from how any other ELF architecture works (e.g. using a single dynamic reloc type for everything with various meanings, etc.) and I have no access to it.

That is what I am afraid of. The MIPS ABI supports "quickstart". I don't know if we can add prelink to mips without breaking/changing the MIPS ABI. I don't want to spend my time on it if it can't be done at all.

H.J.

#5 lore raw
Quoted 6 lines · H . J . Lu
Quoted 2 lines · Jakub Jelinek

instead (well, best would be if somebody ported prelink to mips; I'll try to answer any questions and help).

Do you have some documentations how prelink works?

So far not too much. Some info is in prelink(8) man page, some info was posted to binutils mailing list.
The rest can be done if you ask questions, I'll answer them and save the answers (and compile something from them in the future).

Quoted 5 lines
Quoted 3 lines

I skipped mips because it is way too different from how any other ELF architecture works (e.g. using a single dynamic reloc type for everything with various meanings, etc.) and I have no access to it.

That is what I am afraid of. The MIPS ABI supports "quickstart".

I know, but from what I understood, quickstart e.g. just assumes there won't be conflicts and if there are, their handling is very costly (their conflicts are just symbol indices which need to be checked out). prelink conflicts are ElfW(Rela) relocs against r_symndx 0.

To port prelink to a new architecture, you need basically:
1) determine what you need to do with relocations and special CPU sections when relocating a shared library from one address to another one (e.g. you can link a shared libs once at VMA 0, once at VMA 0xdeadb000 and see what changed) - these are *_adjust_* functions
2) write routines which apply relocs (*_prelink_rel*)
3) write routines which create conflict relocs
4) as MIPS is rel, it needs to be figured out when it is needed to convert from Rel to Rela (in i386/arm case in most cases it can be avoided, the only relocs which require it are (on i386): R_386_32 with nonzero addend (otherwise R_386_GLOB_DAT does exactly the same thing) and R_386_PC32). This is needed, because otherwise the information about the original addend is lost when the final relocated value is stored at r_offset address. Original addend is needed, if prelink cannot be used, during dynamic linking. If MIPS has some place where it stashes this for Quickstart, then it could be reused, otherwise I'm afraid REL->RELA will happen more often on MIPS than on IA-32/ARM.
5) write routines which apply relocs to a buffer or apply a conflict to a buffer (these are used when doing comparisons on relocated content)

Write the glibc part, which for REL arches means write rela variants of routines and figure what if anything needs to be done to undo prelinked PLT slots.

Quoted 3 lines

I don't know if we can add prelink to mips without breaking/changing the MIPS ABI. I don't want to spend my time on it if it can't be done at all.

Jakub

author
#6 lore raw
Quoted 10 lines · Jakub Jelinek
Quoted 6 lines · H . J . Lu
Quoted 2 lines · Jakub Jelinek

instead (well, best would be if somebody ported prelink to mips; I'll try to answer any questions and help).

Do you have some documentations how prelink works?

So far not too much. Some info is in prelink(8) man page, some info was posted to binutils mailing list.

I have prelink-20011010.tar.bz2. Is that current?

Quoted 23 lines
Quoted 6 lines
Quoted 4 lines

I skipped mips because it is way too different from how any other ELF architecture works (e.g. using a single dynamic reloc type for everything with various meanings, etc.) and I have no access to it.

That is what I am afraid of. The MIPS ABI supports "quickstart".

I know, but from what I understood, quickstart e.g. just assumes there won't be conflicts and if there are, their handling is very costly (their conflicts are just symbol indices which need to be checked out). prelink conflicts are ElfW(Rela) relocs against r_symndx 0.

To port prelink to a new architecture, you need basically:
1) determine what you need to do with relocations and special CPU sections when relocating a shared library from one address to another one (e.g. you can link a shared libs once at VMA 0, once at VMA 0xdeadb000 and see what changed) - these are *_adjust_* functions
2) write routines which apply relocs (*_prelink_rel*)
3) write routines which create conflict relocs
4) as MIPS is rel, it needs to be figured out when it is needed to convert from Rel to Rela (in i386/arm case in most cases it can be avoided, the only relocs which require it are (on i386): R_386_32 with nonzero addend (otherwise R_386_GLOB_DAT does exactly the same thing) and

Quoted 9 lines

R_386_PC32). This is needed, because otherwise the information about the original addend is lost when the final relocated value is stored at r_offset address. Original addend is needed, if prelink cannot be used, during dynamic linking. If MIPS has some place where it stashes this for Quickstart, then it could be reused, otherwise I'm afraid REL->RELA will happen more often on MIPS than on IA-32/ARM.
5) write routines which apply relocs to a buffer or apply a conflict to a buffer (these are used when doing comparisons on relocated content)

As I unsterstand, MIPS only has R_MIPS_REL32 for GOT in DSO and EXE. Do you have any suggestions?

H.J.

author
#7 lore raw
Quoted 26 lines · H . J . Lu
Quoted 16 lines

I know, but from what I understood, quickstart e.g. just assumes there won't be conflicts and if there are, their handling is very costly (their conflicts are just symbol indices which need to be checked out). prelink conflicts are ElfW(Rela) relocs against r_symndx 0.

To port prelink to a new architecture, you need basically:
1) determine what you need to do with relocations and special CPU sections when relocating a shared library from one address to another one (e.g. you can link a shared libs once at VMA 0, once at VMA 0xdeadb000 and see what changed) - these are *_adjust_* functions
2) write routines which apply relocs (*_prelink_rel*)
3) write routines which create conflict relocs
4) as MIPS is rel, it needs to be figured out when it is needed to convert from Rel to Rela (in i386/arm case in most cases it can be avoided, the only relocs which require it are (on i386): R_386_32 with nonzero addend (otherwise R_386_GLOB_DAT does exactly the same thing) and

Quoted 9 lines

R_386_PC32). This is needed, because otherwise the information about the original addend is lost when the final relocated value is stored at r_offset address. Original addend is needed, if prelink cannot be used, during dynamic linking. If MIPS has some place where it stashes this for Quickstart, then it could be reused, otherwise I'm afraid REL->RELA will happen more often on MIPS than on IA-32/ARM.
5) write routines which apply relocs to a buffer or apply a conflict to a buffer (these are used when doing comparisons on relocated content)

Quoted 2 lines

As I unsterstand, MIPS only has R_MIPS_REL32 for GOT in DSO and EXE. Do you have any suggestions?

The ld.so relocates R_MIPS_REL32 using GOT which is relocated first by a special rule. There is no relocation information for GOT. Also there is no symbol lookup for relocating R_MIPS_REL32. I am not sure how it will work with the current prelink.

H.J.