RFC: Adding non-PIC executable support to MIPS
[Sorry for the 3-way crosspost!]
One of the big holes in the MIPS ABI has always been the lack of support for non-PIC executables. Any call that might be to a DSO must be made indirectly via $25, and any data that might be defined in a DSO must be accessed via the GOT. MIPS has no PLTs or copy relocations.
There has been talk of changing this at various times over the years. In true bus style, nothing much happened for a long time, then two implementations came along at once. I implemented non-PIC support for Specifix, as part of a more general project to allow MIPS16 code to be used on GNU/Linux. At the same time, CodeSourcery implemented it for Sourcery G++. I only found out about CS's version recently, after finishing the Specifix one, and I think the same is true in reverse. Oh well!
I suppose the good news is that we can pick the best bits of each implementation as the official one. I'll describe my implementation below, then compare it to what I understand CS's version to be. CS folks: please correct me if I'm wrong. Dan said that he'd be submitting CS's version too.
First of all, I should emphasise that this is intended to be a pure ABI extension. Existing objects should continue to work, and existing ET_REL objects should be link-compatible with the new objects.
Example
-------
To take a concrete example, suppose an executable has code like this:
extern void foo (void);
extern int x;
void bar (void) { foo (x); }The compiler has no information about where "foo" and "x" are defined, so for safety's sake, it must assume that they might be defined in a shared library. We are currently forced to generate code like this:
bar:
.set noreorder
lui $28,%hi(__gnu_local_gp)
addiu $28,$28,%lo(__gnu_local_gp)
lw $25,%call16(foo)($gp)
jr $25
lw $4,%got(x)($gp)
.end noreorder(This is the "-mno-shared" form. The "-mshared" version would replace the first two instructions with ".cpload $25" and expect $25 to be valid on entry.)
This is very inefficient if "x" and "foo" turn out to be defined in the executable itself. In contrast, the non-PIC implementation of "bar" is simply:
bar:
.set noreorder
lui $4,%hi(x)
j bar
lw $4,%lo(x)($4)
.end noreorderSo the aim is to allow this non-PIC version of "bar" to be used in dynamic executables. It is the static linker's responsibility to ensure that "bar" works when:
- "x" is defined by a shared library
- "foo" is a PIC function in the same executable
- "foo" is defined by a shared library
It needs help from the dynamic linker to handle the first and third cases.
Copy relocations
----------------
As on most other SVR4 targets, we want to use dynamic relocations for full-word references like:
.data
.word x
However, we want to use copy relocations if the reference is in a read-only section, such as:
.set mips16
lw $2,1f
jr $31
.align 21: .word x
or if the reference is not a full-word one:
lui $2,%hi(x)
addiu $2,$2,%lo(x)Fortunately, VxWorks has already allocated an R_MIPS_COPY relocation type. We can simply extend it to GNU objects as well.
PLTs
----
MIPS has traditionally not used PLTs. Instead, it has a special form of lazy binding stub that is local to the object; unlike a PLT entry, this stub does not participate in name lookup.
These stubs can only be used when all references are through R_MIPS*_CALL* relocations. The GOT slot starts off pointing at the stub, then the stub redirects it to the real function. References like:
.word f
prevent lazy binding.
In contrast, PLTs would allow function references of the forms:
j f
jal f
lui $2,%hi(f)
addiu $2,$2,%lo(f)They would also allow references of the form:
.word f
to be lazily bound.
Adding PLTs gives us three possible ways of referring to an externally-defined function:
- a full-word dynamic relocation (R_MIPS_REL32, possibly combined with R_MIPS_64)
These relocations can only be used if all references are 32-bit ones. They prevent lazy binding, so we only use them for traditional PIC objects.
- a traditional MIPS lazy-binding stub
These stubs can only be used if all references to the function are through R_MIPS*_CALL* relocations. However, they are the most efficient way of handling that situation. Once the function has been resolved, all calls go directly to the real target.
- a PLT stub
PLTs are the fallback, and provide a second, more general, form of lazy binding.
As before, we can appropriate the VxWorks R_MIPS_JUMP_SLOT relocation and use it for GNU objects too.
Many (but not all) targets put .got.plt in the main .got section. I don't think it makes sense to do this for MIPS. We never use $gp-relative accesses for .got.plt, so putting it in .got would steal valuable room in the primary GOT.
DT_JMPREL, DT_PLTREL and DT_PLTSZ describe .rel.plt in the usual way. Objects without PLTs do not have these tags.
At the moment, there are two sorts of GOT header:
- When the top bit of _GLOBAL_OFFSET_TABLE_[1] is clear:
- _GLOBAL_OFFET_TABLE_[0] points to the resolver for the traditional lazy-binding stubs.
- _GLOBAL_OFFSET_TABLE_[1] is the first local or global GOT entry.
This is the traditional SVR4 GOT. glibc still supports it.
- When the top bit of _GLOBAL_OFFSET_TABLE_[1] is set
- _GLOBAL_OFFET_TABLE_[0] points to the resolver for the traditional lazy-binding stubs.
- _GLOBAL_OFFSET_TABLE_[1] is a module pointer.
- _GLOBAL_OFFSET_TABLE_[2] is the first local or global GOT entry.
This is a GNU extension that the linker has used for a long time. glibc keeps the top bit of _GLOBAL_OFFSET_TABLE_[1] set, but uClibc does not.
We need a further GOT entry for resolving PLTs, so the obvious thing is to reserve _GLOBAL_OFFSET_TABLE_[2]. There are then three GOT layouts:
- When the top bit of _GLOBAL_OFFSET_TABLE_[1] is clear:
Layout as before.
- When the top bit of _GLOBAL_OFFSET_TABLE_[1] is set and there is no DT_JMPREL tag:
Layout as before.
- When the top bit of _GLOBAL_OFFSET_TABLE_[1] is set and there is a DT_JMPREL tag.
- _GLOBAL_OFFET_TABLE_[0] points to the resolver for the traditional lazy-binding stubs.
- _GLOBAL_OFFSET_TABLE_[1] is a module pointer.
- _GLOBAL_OFFSET_TABLE_[2] points to the PLT resolver.
- _GLOBAL_OFFSET_TABLE_[3] is the first local or global GOT entry.
The PLT resolver needs to obtain two bits of information:
- the module pointer
- the target function's index in .got.plt/.rel.plt
ARM is another target that places .got.plt separately from .got. Loosely following its example, I used this resolver interface:
$14 : the start of .got.plt
$15 : &_GLOBAL_OFFSET_TABLE_[2]
$24 : the .got.plt entry for the target function
Thus "$15 - sizeof (void *)" points to the module pointer and "($24 - $14) / sizeof (void *)" is the PLT index.
Note that I chose to pass $24 instead of the relocation index itself because we can then use a 4-instruction PLT entry without imposing any limit on the _number_ of PLT entries.
Although the dynamic linker could work out the executable's module pointer without $15, I thought it was better to have an interface that would work for shared libraries too, in case we ever do want to use PLTs for shared libraries in future.
The PLT entry for a function "f" is:
lui $24,%hi(.got.plt slot for f)
lw $25,%lo(.got.plt slot for f)($24)
jr $25
addiu $24,$24,%lo(.got.plt slot for f)The PLT header itself is:
lui $15,%hi(&_GLOBAL_OFFSET_TABLE_[2])
lw $25,%lo(&_GLOBAL_OFFSET_TABLE_[2])($15)
addiu $15,$15,%lo(&_GLOBAL_OFFSET_TABLE_[2])
lui $14,%hi(.got.plt)
jr $25
addiu $14,$14,%lo(.got.plt)The header is followed by 8 bytes of padding so that each PLT entry is 16-byte aligned.
This PLT entry is deliberately not compatible with MIPS I. I thought that fitting the PLT entry into a 16-byte cache line was more important than supporting such an obselete ISA level. Hopefully anyone who still uses MIPS I won't mind sticking to the traditional scheme. (Hi Maciej!)
As on other SVR4 targets, PLT entries have type STT_FUNC and belong to SHN_UNDEF. Unfortunately, as Nigel Stephens pointed out when discussing this a while ago with Dan Jacobowitz and I, this clashes with the traditional MIPS lazy-binding stubs, which also use the STT_FUNC/SHN_UNDEF combination. I followed Nigel's suggestion of adding an STO_MIPS_PLT symbol type to distinguish PLTs from traditional stubs.
Linking PIC and non-PIC in the same object
------------------------------------------
Most targets allow PIC and non-PIC to be linked together, and it would be awkward if MIPS didn't. This means that the static linker has to cope with things like:
a.s (non-PIC):
jal foo
b.s (PIC):
foo:
.cpload $25
...We can handle this situation in two ways. If the target function "foo" starts a section, and the section is not too heavily-aligned, we can insert:
lui $25,%hi(1f)
addiu $25,$25,%lo(1f)1:
immediately before it. This code goes in a new section and is padded with leading nops if necessary. "foo" then resolves to the "lui" instruction, so that all references to "foo" have the same address.
I think this is an important optimisation. In practice, most uses of PIC in executables will come from static libraries, which usually have one function per section.
However, if "foo" doesn't start a section, the linker must create a separate trampoline of the form:
foo:
lui $25,%hi(.pic.foo)
j .pic.foo
addiu $25,$25,%lo(.pic.foo)where .pic.foo is the original PIC form of "foo". Again, "foo" resolves to this trampoline, so that all references to "foo" have the same address.
These trampolines all go in a separate section at the beginning of .text. They are padded with a nop so that each one is aligned to 16 bytes.
ld -r
-----
It should be possible to use "ld -r" to link PIC and non-PIC together into a relocatable object. The result is clearly a non-PIC object, so what do we do with PIC functions? One option would be to add "la $25" prefixes or trampolines to all of them, but that would be inefficient.
I thought it would be better to mark PIC functions with a new st_other value, STO_MIPS_PIC. This allows the final link to distinguish between PIC and non-PIC functions in the same input file.
n32 and n64 GP-load sequences
-----------------------------
n32 and n64 use the idiom:
lui $28,%hi(%neg(%gp_rel(foo)))
addiu $28,$28,%lo(%neg(%gp_rel(foo)))
addu $28,$28,$25to load the value of _gp. Such a reference to foo should not be redirected to an "la $25" stub.
Choice of new STO_* values
--------------------------
For reasons I don't understand, STO_MIPS16 is defined as 0xf0, taking up 4 of the 8 bits in st_other. Visiblity accounts for 2 more. That gives us enough bits to treat STO_MIPS_PLT and STO_MIPS_PIC as orthogonal to both MIPS16ness and visiblity, but we wouldn't have any room left over.
Fortunately, STO_MIPS_PLT, STO_MIPS_PIC are STO_MIPS16 are mutually-exclusive, so we can simply reinterpret the top 4 bits of st_other as an enum. 0x0c would then be free for future extensions.
Identifying non-PIC relocatable objects
---------------------------------------
MIPS has two PICness flags: EF_MIPS_PIC and EF_MIPS_CPIC ("calls PIC"). We can therefore mark non-PIC abicalls objects as:
(flags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC
Assembler directives and command-line interface
-----------------------------------------------
The EF_MIPS_CPIC combination is generated by the assembler directives:
.abicalls
.option pic0
There is no command-line flag to select this mode, so I added one called -call_nonpic. I'm not too tied to that name though.
GCC command-line interface
--------------------------
GCC 4.2 has an "-mno-shared" option. As its name implies, this option can only be used to compile executables. It applies on top of "-mabicalls" and allows GCC to use absolute references for things that it can prove are defined by the executable itself. Functions compiled with "-mno-shared" do not require $25 to be valid on entry, so the compiler can also use direct jumps and calls to functions in the same object file.
Of course, as in the example above, there are many cases in which the compiler cannot prove that something is defined by the executable. The non-PIC support is designed to plug that gap. So, from a conceptual point of view, the new functionality is really a special "-mno-shared" mode; it allows the compiler to use absolute references for all data except TLS.
I decided to add a new pair of GCC options, "-mgnu-plts" and "-mno-gnu-plts", that apply on top of "-mno-shared". There are then four basic forms of o32, n32 and n64 code:
(1) -mno-abicalls
For non-dynamic objects like the linux kernel.
(2) -mabicalls -mno-shared -mgnu-plts
For dynamic executables. Code only uses the global offset table for some models of thread-local storage; it uses absolute accesses for everything else. If it has to call functions indirectly, such as for:
void foo (void (*t) (void)) { t (); }
it continues to call through $25.
This combination requires support from both the static and dynamic linkers.
(3) -mabicalls -mno-shared -mno-gnu-plts
For dynamic executables. Code uses absolute accesses for objects that are defined in the executable itself. It uses direct calls for functions in the same translation unit.
This combination requires support from the static linker. It does not affect the ABI of the final executable.
(4) -mabicalls -mshared
For any dynamic object. This is the traditional SVR4 mode. Note that shared library code must still be compiled with "-fpic" or "-fPIC".
Having four types of executable is complicated, and is not the intended user interface. From the user's perspective, GCC should have the following target-independent interface:
- shared library code is compiled with "-fpic" or "-fPIC";
- position-independent executables are compiled with "-fpie" or "-fPIE"; and
- for efficiency, position-dependent executables are compiled without any of these "-f" flags.
In the last case, GCC should default to the most efficient executable model available. Since 4.3, GCC's configure script automatically checks whether the static linker supports "-mno-shared". It can therefore choose between (3) and (4) without direct intervention.
However, GCC's configure script cannot know whether the dynamic linker supports (2), so we really need a new configure option to choose between "(2)" and "(3) or (4)". I therefore added "--with-gnu-plts" and "--without-gnu-plts", where the latter is the default.
Non-dynamic executables like the linux kernel remain a special case. They must continue to be compiled with "-mno-abicalls".
Linker interface
----------------
The linker should use the new extensions when compiling a non-PIC CPIC executable, but not otherwise. It might be useful to forbid the use of copy relocs and PLTs altogether, so I made -znocopyreloc turn off the extensions.
Linker errors
-------------
Shared-library code must be compiled with "-fpic" or "-fPIC". However, because MIPS compilers have traditionally used (4) as the default executable mode, the sorts of failure you get by forgetting "-fpic" and "-fPIC" have tended to be very subtle. For example, suppose we have:
void foo (void) { ... }
void bar (void) { ... foo (); ... }Without "-fpic" or "-fPIC", GCC will think it can inline foo() into bar(). It will then be impossible for an executable (or for another shared library) to override foo() properly.
The failure for other targets is more drastic, so most cross-target build systems already do the right thing. However, some MIPS-specific build systems might not.
Changing the default executable mode from "(4)" to "(3) or (2)" makes the MIPS failure mode as drastic as it is for other targets. Unfortunately, the MIPS linker has traditionally not checked for accidental uses of absolute code in shared libraries; it would link the following code as a shared library without any diagnostic at all:
lui $4,%hi(x)
addiu $4,$4,%lo(x)The resulting DSO would treat "x" as having the value 0.
This seems too dangerous, so I made the linker complain about any relocation that it cannot resolve itself and that it cannot implement dynamically. The errors have the form:
non-dynamic relocations refer to dynamic symbol FOO
Comparison with the CS implementation
-------------------------------------
I think the main differences with CS's implemention are:
- CS treat .got.plt is part of .got. See above for why I think it should be separate. Note that the PLT header is the same size for both implementations, so the extra parameters don't cost much.
- CS PLT entries pass a PLT index rather than a .got.plt address. This makes no difference for most objects, but a longer stub is needed if there are more than 0x10000 PLT entries.
- I couldn't see any specific support for ld -r in the CS version.
- The CS version always uses separate "la $25" trampolines, rather than adding instructions to the beginning of a function. This is an implementation rather than an ABI detail though.
- CS support MIPS I, at the cost of using the start of the next PLT entry as a delay slot instruction.
- STO_MIPS_PLT is separate from STO_MIPS16.
This comparison is based on 4.2-129 and I've probably got it wrong.
I'm not sure if CS's version supports n32 and n64, but adding it wouldn't be a big issue.
Patches
-------
In case it helps the discussion, I've attached patches for binutils, gcc and glibc. I'm not asking for approval though.
Each set of patches has prerequisites that haven't been applied yet. I've therefore attached them in the form of a bzipped quilt. The patches with .clog changelog files are the ones related to non-PIC support.
The glibc patches are based on EGLIBC 2.6.
Richard
Quoted 4 lines · Richard Sandiford
[Sorry for the 3-way crosspost!]
One of the big holes in the MIPS ABI has always been the lack of support for non-PIC executables.
...
Quoted 3 lines
I'll describe my implementation
below, then compare it to what I understand CS's version to be. CS folks: please correct me if I'm wrong.
This sounds like really good stuff and, on first reading, it all seems to make sense to me. My only real concern is documentation of these changes. The MIPS ABI (http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf) is currently moribund. The document that describes it hasn't been updated in since 1996 and gcc is not fully conformant (see, for example, the assumptions required for correct stack backtracing). It would take significant work to resurrect this but it certainly would be helpful to have a current document that completely describes the MIPS ABI, or at least the current ELF format, as currently implemented on Linux, especially if it is to be extended. The logical home for something like this would probably be the Linux Standard Base project hosted by the Linux Foundation.
Signature · 8 lines
David VomLehn, [email protected] The opinions expressed herein are likely mine, but might not be my employer's... - - - - - Cisco - - - - - This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.
Quoted 2 lines · David VomLehn
This sounds like really good stuff and, on first reading, it all seems to make sense to me. My only real concern is documentation of these changes.
FWIW, I'll be posting our version of this project shortly, and it includes an ABI supplement. Supplemental to a somewhat hypothetical document, but there you go...
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
Quoted 6 lines · Daniel Jacobowitz
Quoted 1 line · David VomLehn
This sounds like really good stuff and, on first reading, it all seems to make sense to me. My only real concern is documentation of these changes.
FWIW, I'll be posting our version of this project shortly, and it includes an ABI supplement. Supplemental to a somewhat hypothetical document, but there you go...
Also, FWIW, if there is interest in trying to get an Linux Standard Base working group for the MIPS Processor, one of the LSB Steering Committee members used to be Chair of the MIPS ABI Group Technical Committee, which wrote the MIPS ABI. And, uh, yeah, I'll admit it, I used to chair the TC, too, once upon a time. So, we actually still have some people around who at least used to know something about it...
Signature · 8 lines
David VomLehn, [email protected] The opinions expressed herein are likely mine, but might not be my employer's... - - - - - Cisco - - - - - This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.
Quoted 4 lines · Richard Sandiford
used on GNU/Linux. At the same time, CodeSourcery implemented it for Sourcery G++. I only found out about CS's version recently, after finishing the Specifix one, and I think the same is true in reverse. Oh well!
Yes, that's right - first I heard about this was last week :-(
Quoted 5 lines
I suppose the good news is that we can pick the best bits of each implementation as the official one. I'll describe my implementation below, then compare it to what I understand CS's version to be. CS folks: please correct me if I'm wrong. Dan said that he'd be submitting CS's version too.
Indeed, and here it is. I have attached patches for gcc, binutils, gdb, glibc (EGLIBC trunk but likely to apply fine to FSF GLIBC also), and glibc-ports (ditto). There's also a build fix for EGLIBC after Richard's recent change to the "h" constraint (similar to the one in Richard's eglibc quilt). I have also included the ABI writeup we used. Changelogs are missing for the binutils/gcc patches.
The patches were written by Mark Shinwell, Catherine Moore, and myself. The ABI document was originally written by Nigel Stephens of MIPS Technologies, Inc., who sponsored this project; I've updated it as we went along. Richard, Nigel, and I discussed a version of this document in 2007; it has changed slightly. I've had to do some last minute updates to it today to match the implementation, so I sincerely hope I got them right.
Most descripions of Richard's implementation also apply to ours. It is compatible with both existing ET_REL objects and existing ET_EXEC/ET_DYN modules. Old binaries continue to work with a patched C library, existing static libraries can still be used by the new linker, et cetera.
Quoted 2 lines
Comparison with the CS implementation
-------------------------------------
Some similarities first: R_MIPS_COPY / R_MIPS_JUMP_SLOT, STO_MIPS_PLT, EF_MIPS_CPIC, use of .option pic0, the need for linker errors on non-PIC, the grotty glibc hack to make it check STO_MIPS_PLT (Richard's duplicates more code, but is considerably less grotty; had we realized we'd be stuck with a copy of dl-lookup.c I would likely not have written the awful preprocessor trick you'll see in the ports patch).
Quoted 5 lines
I think the main differences with CS's implemention are:
- CS treat .got.plt is part of .got. See above for why I think it should be separate. Note that the PLT header is the same size for both implementations, so the extra parameters don't cost much.
No, we don't - they're on opposite sides of .data. We reserve two words at the start of the PLT GOT in addition to the two at the beginning of the GOT. The PLT header loads the start of .got.plt and passes that to _dl_runtime_pltresolve in $gp. The return address is passed in $t9 and the index in $t8.
Quoted 3 lines
- CS PLT entries pass a PLT index rather than a .got.plt address. This makes no difference for most objects, but a longer stub is needed if there are more than
0x10000PLT entries.
Yes, this was chosen in order to support MIPS I while still fitting the PLT entries on a single cache line.
Quoted 1 line
- I couldn't see any specific support for ld -r in the CS version.
That's right, we do not support this. I've no complaint about gaining support :-) Given the requirement, STO_MIPS_PIC seems sensible.
Quoted 3 lines
- The CS version always uses separate "la $25" trampolines, rather than adding instructions to the beginning of a function. This is an implementation rather than an ABI detail though.
Right.
Quoted 2 lines
- CS support MIPS I, at the cost of using the start of the next PLT entry as a delay slot instruction.
FWIW it also adds one instruction to the header; that's why the delay slot of the branch is empty.
Quoted 1 line
-
STO_MIPS_PLTis separate fromSTO_MIPS16.
Right.
Quoted 4 lines
This comparison is based on 4.2-129 and I've probably got it wrong.
I'm not sure if CS's version supports n32 and n64, but adding it wouldn't be a big issue.
Right - it's not there, but we figured we'd add it at some not-too-future date.
Also:
- We reserve two words at the start of the PLT GOT rather than pass another argument to the resolver. One of them points to the PLT resolver, and the other to the link map (from which the dynamic linker can look up whatever it needs).
- One of the new dynamic tags, DT_MIPS_PLTGOT, exists solely to let the dynamic linker fill in those two reserved entries. So this tag is required.
- The other dynamic tag, DT_MIPS_RWPLT, is for a specified but unimplmented optimization a la PowerPC-32 - rewriting resolved PLT entries to a direct jump.
OK, that's the ABI comparison. These are what I'm concerned about for integrating the two versions; all implementation differences I know we can decide case-by-case. And because both Richard's and our versions apply this behavior by default based on a configure option, I'm not concerned with the command line options or spelling of configure options either.
We've shipped our version. Richard's version has presumably also shipped. We did negotiate the ABI changes with MTI; this is not quite as good as doing it in full view, but it was the best we could manage and MTI is as close to a central authority for the MIPS psABI as exists today.
Richard, what are your thoughts on reconciling the differences? You can surely guess that I want to avoid changing our ABI now, even for relatively significant technical reasons - I'm all ears if there's a major reason, but in the comparisons I do not see one.
If necessary, one of us can end up with a compatibility layer at runtime thanks to DT_MIPS_RWPLT :-(
Comments welcome from all.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
====
MIPS non-PIC ABI specification
====
Introduction
----
This document describes the specification of the new MIPS ABI to provide absolute (non-PIC) addressing as used for Linux applications on most architectures. MIPS currently uses the existing psABI that mandates compilation of applications as position-independent code.
The intention is that this extension to the ABI will be a strict superset of the existing MIPS o32 psABI for non-PIC executables, and will not break compatibility with legacy PIC object files, allowing interlinking of new-model and legacy object files both statically and dynamically (apart from ld.so, of course).
This document does not cover n32 and n64 ABIs; they are expected to be a straightforward extension of the same design.
At this time we do not propose any change to the position-independent addressing conventions used by shared objects. Similarly, position-independent executables compiled with '-fpie' -- as required for address space randomisation in "hardened" Linux distributions -- shall continue to use the existing psABI addressing and calling mechanisms.
Identification of Object Files
----
Object files which use this new ABI extension will need to be identifiable. They will have EF_MIPS_CPIC set and EF_MIPS_PIC clear in the ELF header's e_flags field. The dynamic linker can identify new-model executables which use the PLT mechanism by the existence of DT_JMPREL tag in the dynamic table. It is also suggested that the EI_ABIVERSION entry in the ELF header ident be incremented from 0 to 1 for such executables, so that existing dynamic linkers will refuse to link them, and display a "helpful" error message rather than linking them incorrectly and having the application crash.
[Ed. note: this does not actually work with glibc's ld.so for executables; it does not check the ABI version of the executable, or checks it too late.]
Procedure Linkage Table
----
The Procedure Linkage Table (PLT) consists of a set of stubs generated by the static linker to stand in for external functions that are in a shared object. They can be called using an absolute JAL instuction and then redirect the call from the executable to the actual function via a pointer in the PLT GOT (the .got.plt section which holds 32-bit function pointers only).
The PLT is output to the .plt section, which section should be aligned to a 32 byte boundary so that all PLT entries occupy no more than one cache line.
The PLT GOT holds function addresses used by the PLT stubs, and the PLT GOT entries shall be initialised by the static linker to point to the PLT header (i.e. the base of the .plt section). In this way the first call to an external function will invoke the dynamic linker to resolve the symbol and update the corresponding PLT GOT entry; the next call will then jump from the PLT straight to the function, avoiding the dynamic linker.
In the existing version of the ABI, as implemented by glibc, the first two GOT entries are reserved:
GOT[0]
Pointer to dynamic linker's GOT resolver which takes a dynamic symbol index argument.
GOT[1]
Pointer to this object's link map
In this ABI, the GOT layout will remain the same. The first two entries in the PLT GOT will be reserved as follows:
PLTGOT[0]
Pointer to dynamic linker's PLT resolver (which takes a PLT index argument instead of the dynamic symbol index used by the GOT resolver).
PLTGOT[1]
Pointer to this object's link map.
Since PLT entries use absolute addresses to access the PLT GOT, the PLT GOT does not need to be located within 32K of the _gp symbol. Indeed it would be better to prevent the PLT GOT from occupying this scarce resource in the address map. There is no requirement for the PLT GOT and GOT to be consecutive.
For each PLT entry a R_MIPS_JUMP_SLOT relocation entry shall be output to the dynamic .rel.plt section: the relocation entry's dynamic symbol index specifies the symbol to which the PLT entry refers, and the offset field holds the address of the PLT entry. An addend is never required (so we remain with REL relocs). The PLT index passed by the PLT to the dynamic linker is both an index into the array of jump slot relocations, and can be transformed into
an index into the PLT GOT by adding two (corresponding to the reserved PLT resolver and link map slots at PLTGOT[0] and PLTGOT[1]). Dynamic
symbol table entries referenced only by jump slot or copy relocations shall precede the "GOT mapped" symbols whose first index is specified by the DT_MIPS_GOTSYM dynamic table entry.
PLT Header
----
The first entry in the PLT handles the first call to a PLT only, and is 32 bytes in size::
PLT0: lui gp, %hi(.got.plt) # linker needs address of
addiu gp, %lo(.got.plt) # .got.plt to find link map
lw t9, 0(gp) # PLTGOT[0] == &_dl_runtime_pltresolve()
move t7,ra # linker needs caller's address
jalr t9 # call _dl_runtime_pltresolve()
nop # bdslot
nop # spare
nop # spare
PLT Type A
''''
If the maximum PLT index is less than or equal to 65535, then a minimum length PLT of 16 bytes can be generated::
PLT1: lui t7, %hi(%pltgot(name1)) # high PLT GOT pointer
lw t9, %lo(%pltgot(name1))(t7) # load func pointer from PLT GOT
ori t8, $0, index1 # load plt index (ldslot)
jr t9 # jump to func
PLT2: lui t7, %hi(%pltgot(name2) # (bdslot)
lw t9, %lo(%pltgot(name2))(t7)
ori t8, $0, index2
jr t9
PLT3: ...
PLTn: nop; nop; nop; nop
(Note that this is effectively pseudocode; the assembler does not need modifying to understand "%pltgot(...)" since these instructions will be directly written out by the linker.)
PLT Type B
''''
When the maximum PLT index is greater than 65535, a large PLT is required, rounded up to 32 bytes in length::
PLT1: lui t7, %hi(%pltgot(name1)) # high PLT GOT pointer
lw t9, %lo(%pltgot(name1))(t7) # load func pointer from PLT GOT
lui t8, index1>>16 # load hi plt index (ldslot)
jr t9 # jump to func
ori t8, t8, index1&0xffff # load lo plt index (bdslot)
nop
nop
nop
Writable PLT Fixup
----
PLT Type C
''''
After resolving the symbol and updating the PLT GOT, then if the PLT is in a writable section, the dynamic linker shall patch the PLT to use the absolute address of the function, thereby avoiding the PLT GOT reference, as follows. The dynamic linker can detect a writable PLT by the existence of a non-null DT_MIPS_RWPLT entry in the dynamic table::
PLT1: lui t9, %hi(name1)
addiu t9, %lo(name1)
jr t9
nop
PLT Type D
''''
Furthermore if the address at which the function is loaded lies within the same 256MB segment as the PLT entry, then it can avoid the indirect jump also::
PLT1: lui t9, %hi(name1)
j name1
addiu t9, %lo(name1)
nop
Note that the base MIPS32 and MIPS64 MMU does not provide a "no-execute" bit, and therefore cannot support the "least privilege" page protection model required by "Hardened" Linux features such as Exec Shield and PAX. [Actually the SmartMIPS ASE specifies the execute-inhibit (XI) bit, but that's only available in the 4KSd core.] However the static linker should be capable of generating a non-writable (secure) PLT and GOT to conform with SELinux restrictions, and on a SmartMIPS core this could be used to prevent writable data areas from becoming executable. This would be at the cost of some loss of performance for external function calls.
Function addresses
----
To allow comparison of function addresses to work as expected, it is necessary for the executable and all shared objects to see the same function address. If the executable takes the address of an external function it will generate a PLT entry for that function, and that PLT entry must then be the canonical address for the function throughout the program.
Taking the address of an external function in a non-PIC executable will result in a symbol table entry with type STT_FUNC and section index of SHN_UNDEF, but with a non-zero st_value field that holds the address of the function's PLT entry; furthermore the new STO_MIPS_PLT bit shall be set in the symbol's st_other field. If the function's address is not referenced (i.e. the function is only ever called by the executable), then the symbol's st_value field will be zero and the STO_MIPS_PLT bit clear.
The dynamic linker will use an undefined function symbol table entry with STO_MIPS_PLT set to resolve all references to that symbol in preference to the actual definition of that symbol, except when resolving an R_MIPS_JUMP_SLOT relocation.
Note that this is the opposite behaviour to the legacy MIPS psABI where an undefined function symbol table entry with a zero st_value field indicates that there is an address reference to the function and the dynamic linker must resolve the symbol immediately upon loading; and where undefined function entries are always ignored when searching for a symbol definition.
Dynamic Section
----
Dynamic section entries give information to the dynamic linker. Some of the information is processor-specific, including the interpretation of some entries in the dynamic structure. The following new or changed dynamic table entries are required by the extended ABI:
DT_JMPREL (23)
Previously unused for MIPS, now points to the first jump-slot relocation in the dynamic relocation table (i.e. the base of .rel.plt).
DT_PLTREL (20)
Previously unused for MIPS, now with a value of DT_REL indicating that DT_JMPREL points to REL relocations.
DT_PLTRELSZ (2)
Previously unused for MIPS, now holding the size of .rel.plt in bytes.
DT_MIPS_PLTGOT (0x70000032)
(New) Points to the base of the PLT GOT (.got.plt section), since it may not be contiguous with the traditional GOT (.got section). The standard DT_PLTGOT entry points to the base of the GOT.
DT_MIPS_RWPLT (0x70000034)
(New) Points to the base of the PLT when the PLT is writable; for a non-writable PLT it is omitted or has a zero value.
The dynamic symbol table may have undefined function entries with the following bit set in the st_other field:
STO_MIPS_PLT (0x8)
(New) Symbol value is the address of a PLT entry.
The dynamic relocation table may now contain two new relocation types generated by the static linker:
R_MIPS_COPY (126)
A data copy relocation.
R_MIPS_JUMP_SLOT (127)
A PLT relocation.
External Data
----
If a non-PIC executable contains a reference to a data symbol in a shared object, then the static linker shall allocate space for that symbol in the executable's writable .dynbss (or .dynsbss) section, and output an R_MIPS_COPY relocation entry to the dynamic relocation section. The offset field of the relocation entry gives the address of the data in the .dynbss section. During execution the dynamic linker will copy any initial data associated with the shared object's symbol to the location specified by the offset, and point all GOT entries that refer to that symbol to the executable's copy.
Large Code Size
----
The 26-bit offset of a MIPS absolute JAL and J instruction would limit the executable's code (including the PLT) to fit in a single 256MB address segment. That's sufficient for most embedded applications, but could be exceeded by some larger "server" applications. This may be handled by explicitly compiling large applications with '-mlongcalls'.
A more elegant solution would be for the linker to automatically insert trampolines when a call site and the function (or its PLT) are not within the same 256MB segment, similar to the mechanism used for the PPC32 architecture. This may be implemented at a later date and has no ABI implications.
Small Data
----
An optimisation available to statically-linked "bare iron" applications is to place data with size no greater than some threshold (default 8 bytes) in a small data section, where it can be referenced using short offsets from the $gp register. In Dhrystone the lack of small data addressing accounts for approximately one eighth of the 30% performance differential between bare-iron and Linux.
Enabling small data addressing for non-PIC executables will enable some but not all of this performance to be regained, particularly in functions which reference many small global variables. Because shared libraries use the $gp register to hold their GOT pointer, the register will not be constant throughout the application, so the compiler must reload the small data pointer whenever required by a function. Note that "small" external data must be allocated in the executable's .dynsbss section, instead of the .dynbss section.
Since this is a local optimisation the compiler may use an arbitrary register to hold the small data pointer: it could be any call-clobbered register, or a call-saved register if its use crosses a function call.
The compiler might choose not to use a small data pointer register if it can determine that there is only one reference to small data in a function, in which case it will be faster to use an absolute address.
For non-PIC executables the compiler may now consider $gp to be a call-clobbered register that it is free to allocate for any purpose.
Legacy psABI support
----
While new-model code will use the PLT to reference external functions, any legacy PIC code with which it is statically linked should continue to use the linker-generated call stubs in the .MIPS.stubs section, rather than referencing the new-model PLT. This is to avoid the penalty of a double indirection when calling the function:
i.e. calling indirectly via the GOT to the PLT, and then the PLT calling the actual function via the PLT GOT.
The exception to this is if the non-PIC code references the same function, in which case the PIC code must generate a local GOT entry which points to the associated PLT entry. [A possible optimisation, if we are willing to have both a PLT GOT and GOT entry referencing the same function, is to only point the GOT to the PLT only if there are relocations other than R_MIPS_26, R_MIPS_CALL16 or R_MIPS_GOT16 referencing the function, and otherwise use a global GOT entry pointing directly to the function.]
Similarly for access to external data, if the non-PIC code generates an R_MIPS_COPY relocation for a symbol, then PIC code referencing the same symbol must allocate a local GOT entry pointing to the executable's copy of the data in .dynbss or .dynsbss. Otherwise a global GOT entry shall be allocated to point to the symbol.
Finally, if the non-PIC executable references a function in the statically-linked PIC code, then it will be necessary for the linker to allocate a call stub which first loads the $t9 register with the function's address, for use by non-PIC caller. The call stub would look like PLT style C or D above, and could be allocated in the PLT or .MIPS.stubs section, or any other part of the text section. If the function is globally binding, and is referenced by a non-PIC, non-call relocation, then its symbol table entry must point to the call stub, so that the stub is the canonical address of the function.
configure +7 -0
@@ -1048,6 +1048,7 @@ Optional Features: arrange to use setjmp/longjmp exception handling --enable-secureplt enable -msecure-plt by default for PowerPC --enable-cld enable -mcld by default for 32bit x86 + --enable-mips-nonpic enable non-PIC ABI by default for MIPS GNU/Linux o32 --disable-win32-registry disable lookup of installation paths in the Registry on Windows hosts
@@ -13779,6 +13780,12 @@ else enable_cld=no fi; +# Check whether --enable-mips-nonpic or --disable-mips-nonpic was given. +if test "${enable_mips_nonpic+set}" = set; then + enableval="$enable_mips_nonpic" + +fi; + # Windows32 Registry support for specifying GCC installation paths. # Check whether --enable-win32-registry or --disable-win32-registry was given. if test "${enable_win32_registry+set}" = set; then
testsuite/gcc.target/mips/lazy-binding-1.c +1 -1
@@ -1,5 +1,5 @@/* { dg-do compile { target nomips16 } } */ -/* { dg-mips-options "-mabicalls -mshared -mexplicit-relocs -O2 -fno-delayed-branch" } */ +/* { dg-mips-options "-mabicalls -mshared -fpic -mexplicit-relocs -O2 -fno-delayed-branch" } */ void bar (void );
testsuite/gcc.target/mips/mips-nonpic/nonpic-addr.c +9 -0
@@ -0,0 +1,9 @@ +extern void nonpic_nothing (void ); +extern int hit_nonpic_addr; +void +nonpic_addr () +{ +nonpic_receive_fn_addr (&nonpic_nothing); + hit_nonpic_addr++; +return ; +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-call.c +10 -0
@@ -0,0 +1,10 @@ +extern void pic_nothing (void ); +extern void pic_addr (void ); +extern int hit_nonpic_call; +void +nonpic_call () +{ +pic_nothing (); +pic_addr (); + hit_nonpic_call++; +}
testsuite/gcc.target/mips/mips-nonpic/pic-receive-fn-addr.c +9 -0
@@ -0,0 +1,9 @@ +extern void pic_nothing (void ); +extern void abort (void ); +void +pic_receive_fn_addr (void *x) +{ +if (x != &pic_nothing) +abort (); +return ; +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-10.c +25 -0
@@ -0,0 +1,25 @@ +/* { dg-options "nonpic-call.o pic-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_call (); +extern void pic_addr (); +int hit_nonpic_call =0 ; +int hit_pic_addr =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +extern void exit (int ); +extern void abort (void ); + +main () +{ +nonpic_call (); +pic_addr (); + +if (hit_nonpic_call !=1 ) +abort (); + +if (hit_pic_addr !=2 ) +abort (); + +exit (0 ); + +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-11.c +23 -0
@@ -0,0 +1,23 @@ +/* { dg-options "nonpic-addr.o pic-addr.o nonpic-receive-fn-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_addr (); +extern void pic_addr (); +extern void exit (int ); +extern void abort (void ); +int hit_nonpic_addr =0 ; +int hit_pic_addr =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +main () +{ +nonpic_addr (); +pic_addr (); + +if (hit_nonpic_addr !=1 ) +abort (); + +if (hit_pic_addr !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-12.c +23 -0
@@ -0,0 +1,23 @@ +/* { dg-options "nonpic-addr-call.o pic-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_nonpic_addr_call =0 ; +int hit_pic_addr =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +extern void nonpic_addr_call (); +extern void pic_addr (); +extern void abort (void ); +extern void exit (int ); +main () +{ +nonpic_addr_call (); +pic_addr (); + +if (hit_nonpic_addr_call !=1 ) +abort (); + +if (hit_pic_addr !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/mips-nonpic.exp +45 -0
45 lines not on this page · raw message
testsuite/gcc.target/mips/mips-nonpic/nonpic-addr-call.c +10 -0
@@ -0,0 +1,10 @@ +extern int hit_nonpic_addr_call; +extern void pic_nothing (void ); +extern void pic_receive_fn_addr (void *); +void +nonpic_addr_call (void ) +{ + hit_nonpic_addr_call++; +pic_receive_fn_addr (&pic_nothing); +return ; +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-13.c +21 -0
@@ -0,0 +1,21 @@ +/* { dg-options "pic-addr-call.o nonpic-receive-fn-addr.o nonpic-nothing.o" } */ + +int hit_pic_addr_call =0 ; +int hit_nonpic_nothing =0 ; +extern void nonpic_nothing (); +extern void pic_addr_call (); +extern void exit (int ); +extern void abort (void ); +main () +{ +nonpic_nothing (); +pic_addr_call (); + +if (hit_nonpic_nothing !=1 ) +abort (); + +if (hit_pic_addr_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-14.c +24 -0
@@ -0,0 +1,24 @@ +/* { dg-options "nonpic-call.o pic-addr.o pic-receive-fn-addr.o pic-addr-call.o nonpic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_pic_addr_call =0 ; +int hit_nonpic_call =0 ; +int hit_pic_addr =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +extern void nonpic_call (); +extern void pic_addr_call (); +extern void abort (void ); +extern void exit (int ); +main () +{ +nonpic_call (); +pic_addr_call (); + +if (hit_nonpic_call !=1 ) +abort (); + +if (hit_pic_addr_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-15.c +23 -0
@@ -0,0 +1,23 @@ +/* { dg-options "nonpic-addr.o pic-receive-fn-addr.o pic-addr-call.o nonpic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_pic_addr_call =0 ; +int hit_nonpic_addr =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +extern void nonpic_addr (); +extern void pic_addr_call (); +extern void abort (void ); +extern void exit (int ); +main () +{ +nonpic_addr (); +pic_addr_call (); + +if (hit_nonpic_addr !=1 ) +abort (); + +if (hit_pic_addr_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-16.c +21 -0
@@ -0,0 +1,21 @@ +/* { dg-options "nonpic-addr-call.o pic-receive-fn-addr.o pic-addr-call.o nonpic-receive-fn-addr.o pic-nothing.o nonpic-nothing.o" } */ + +extern void abort (void ); +extern void exit (int ); +extern void nonpic_addr_call (); +extern void pic_addr_call (); +int hit_nonpic_addr_call =0 ; +int hit_pic_addr_call =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +main () +{ +nonpic_addr_call (); +pic_addr_call (); + +if (hit_nonpic_addr_call !=1 ) +abort (); +if (hit_pic_addr_call !=1 ) +abort (); +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-receive-fn-addr.c +8 -0
@@ -0,0 +1,8 @@ +extern void nonpic_nothing (void ); +extern void abort (void ); +void +nonpic_receive_fn_addr (void *x) +{ +if (x != &nonpic_nothing) +abort (); +}
testsuite/gcc.target/mips/mips-nonpic/pic-nothing.c +7 -0
@@ -0,0 +1,7 @@ +extern int hit_pic_nothing; +void +pic_nothing () +{ + hit_pic_nothing++; +return ; +}
testsuite/gcc.target/mips/mips-nonpic/pic-addr.c +9 -0
@@ -0,0 +1,9 @@ +extern int hit_pic_addr; +extern void pic_nothing (void ); +void +pic_addr () +{ +pic_receive_fn_addr (&pic_nothing); + hit_pic_addr++; +return ; +}
testsuite/gcc.target/mips/mips-nonpic/pic-call.c +10 -0
@@ -0,0 +1,10 @@ +extern int hit_pic_call; +extern void nonpic_nothing (void ); +extern void nonpic_addr (void ); +void +pic_call () +{ +nonpic_nothing (); +nonpic_addr (); + hit_pic_call++; +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-1.c +21 -0
@@ -0,0 +1,21 @@ +/* { dg-options "pic-nothing.o nonpic-nothing.o" } */ + +extern void nonpic_nothing (); +extern void pic_nothing (); +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +extern void exit (int ); +extern void abort (void ); +main () +{ +nonpic_nothing (); +pic_nothing (); + +if (hit_nonpic_nothing !=1 ) +abort (); + +if (hit_pic_nothing !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-2.c +23 -0
@@ -0,0 +1,23 @@ +/* { dg-options "pic-addr.o nonpic-call.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_call (); +extern void pic_nothing (); +extern void abort (void ); +extern void exit (int ); +int hit_nonpic_call =0 ; +int hit_pic_nothing =0 ; +int hit_pic_addr =0 ; +int hit_nonpic_nothing =0 ; +main () +{ +nonpic_call (); +pic_nothing (); + +if (hit_nonpic_call !=1 ) +abort (); + +if (hit_pic_nothing !=2 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-3.c +22 -0
@@ -0,0 +1,22 @@ +/* { dg-options "nonpic-addr.o nonpic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_addr (); +extern void pic_nothing (); +extern void abort (void ); +extern void exit (int ); +int hit_nonpic_addr =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +main () +{ +nonpic_addr (); +pic_nothing (); + +if (hit_nonpic_addr !=1 ) +abort (); + +if (hit_pic_nothing !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-4.c +24 -0
@@ -0,0 +1,24 @@ +/* { dg-options "pic-addr.o pic-receive-fn-addr.o nonpic-addr-call.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_nonpic_addr_call =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_addr =0 ; +int hit_nonpic_addr =0 ; +extern void nonpic_addr_call (); +extern void pic_nothing (); +extern void exit (int ); +extern void abort (void ); +main () +{ +nonpic_addr_call (); +pic_nothing (); + +if (hit_nonpic_addr_call !=1 ) +abort (); + +if (hit_pic_nothing !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-5.c +24 -0
@@ -0,0 +1,24 @@ +/* { dg-options "pic-addr.o pic-call.o nonpic-addr.o pic-receive-fn-addr.o nonpic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_nothing (); +extern void pic_call (); +extern void exit (int ); +extern void abort (void ); +int hit_nonpic_nothing =0 ; +int hit_pic_call =0 ; +int hit_nonpic_addr =0 ; +int hit_pic_nothing =0 ; +int hit_pic_addr =0 ; +main () +{ +nonpic_nothing (); +pic_call (); + +if (hit_nonpic_nothing !=2 ) +abort (); + +if (hit_pic_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-6.c +26 -0
@@ -0,0 +1,26 @@ +/* { dg-options "pic-call.o nonpic-call.o nonpic-addr.o pic-addr.o nonpic-receive-fn-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_call (); +extern void pic_call (); +extern void exit (int ); +extern void abort (void ); +int hit_pic_call =0 ; +int hit_nonpic_call =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +int hit_nonpic_addr =0 ; +int hit_pic_addr =0 ; + +main () +{ +pic_call (); +nonpic_call (); + +if (hit_pic_call !=1 ) +abort (); + +if (hit_nonpic_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-7.c +23 -0
@@ -0,0 +1,23 @@ +/* { dg-options "pic-call.o nonpic-addr.o nonpic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_pic_call =0 ; +int hit_nonpic_addr =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +extern void nonpic_addr (); +extern void pic_call (); +extern void exit (int ); +extern void abort (void ); +main () +{ +pic_call (); +nonpic_addr (); + +if (hit_pic_call !=1 ) +abort (); + +if (hit_nonpic_addr !=2 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-nothing.c +7 -0
@@ -0,0 +1,7 @@ +extern int hit_nonpic_nothing; +void +nonpic_nothing () +{ + hit_nonpic_nothing++; +return ; +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-8.c +24 -0
@@ -0,0 +1,24 @@ +/* { dg-options "pic-call.o nonpic-addr-call.o nonpic-addr.o nonpic-receive-fn-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +int hit_nonpic_addr_call =0 ; +int hit_pic_call =0 ; +int hit_pic_nothing =0 ; +int hit_nonpic_nothing =0 ; +int hit_nonpic_addr =0 ; +extern void exit (int ); +extern void abort (void ); +extern void nonpic_addr_call (); +extern void pic_call (); +main () +{ +pic_call (); +nonpic_addr_call (); + +if (hit_pic_call !=1 ) +abort (); + +if (hit_nonpic_addr_call !=1 ) +abort (); + +exit (0 ); +}
testsuite/gcc.target/mips/mips-nonpic/nonpic-9.c +15 -0
@@ -0,0 +1,15 @@ +/* { dg-options "pic-addr.o pic-receive-fn-addr.o nonpic-nothing.o pic-nothing.o" } */ + +extern void nonpic_nothing (); +extern void pic_addr (); +extern void exit (int ); +extern void abort (void ); +int hit_pic_addr =0 ; +int hit_nonpic_nothing =0 ; +int hit_pic_nothing =0 ; +int hit_pic_receive_fn_addr =0 ; +main () +{ +pic_addr (); +nonpic_nothing (); +}
testsuite/gcc.target/mips/mips-nonpic/pic-addr-call.c +10 -0
@@ -0,0 +1,10 @@ +extern int hit_pic_addr_call; +extern void nonpic_nothing (void ); +extern void nonpic_receive_fn_addr (void *); +void +pic_addr_call (void ) +{ + hit_pic_addr_call++; +nonpic_receive_fn_addr (&nonpic_nothing); +return ; +}
configure.ac +4 -0
@@ -1537,6 +1537,10 @@ AC_ARG_ENABLE(cld, [ --enable-cld enable -mcld by default for 32bit x86], [], [enable_cld=no]) +AC_ARG_ENABLE(mips-nonpic, +[ --enable-mips-nonpic enable non-PIC ABI by default for MIPS GNU/Linux o32], +[], []) + # Windows32 Registry support for specifying GCC installation paths. AC_ARG_ENABLE(win32-registry, [ --disable-win32-registry
config.gcc +12 -4
@@ -1489,7 +1489,7 @@ mcore-*-pe*) mips-sgi-irix[56]*) tm_file="elfos.h ${tm_file} mips/iris.h" tmake_file="mips/t-iris mips/t-slibgcc-irix" - target_cpu_default="MASK_ABICALLS" + tm_defines="${tm_defines} TARGET_ABICALLS_DEFAULT=1" case ${target} in *-*-irix5*) tm_file="${tm_file} mips/iris5.h"
@@ -1515,12 +1515,16 @@ mips-sgi-irix[56]*) use_fixproto=yes ;; mips*-*-netbsd*) # NetBSD/mips, either endian. - target_cpu_default="MASK_ABICALLS" + tm_defines="${tm_defines} TARGET_ABICALLS_DEFAULT=1" tm_file="elfos.h ${tm_file} mips/elf.h netbsd.h netbsd-elf.h mips/netbsd.h" ;; mips64*-*-linux*) tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h mips/linux64.h" tmake_file="${tmake_file} mips/t-linux64" + tm_defines="${tm_defines} TARGET_ABICALLS_DEFAULT=1" + if test x${enable_mips_nonpic}; then + tm_defines="${tm_defines} TARGET_ABICALLS_NONPIC=1" + fi tm_defines="${tm_defines} MIPS_ABI_DEFAULT=ABI_N32" case ${target} in mips64el-st-linux-gnu)
@@ -1533,7 +1537,11 @@ mips64*-*-linux*) test x$with_llsc != x || with_llsc=yes ;; mips*-*-linux*) # Linux MIPS, either endian. - tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h" + tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h" + tm_defines="${tm_defines} TARGET_ABICALLS_DEFAULT=1" + if test x${enable_mips_nonpic}; then + tm_defines="${tm_defines} TARGET_ABICALLS_NONPIC=1" + fi case ${target} in mipsisa32r2*) tm_defines="${tm_defines} MIPS_ISA_DEFAULT=33"
@@ -1545,7 +1553,7 @@ mips*-*-linux*) # Linux MIPS, either ;; mips*-*-openbsd*) tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_OBJECT OBSD_HAS_CORRECT_SPECS" - target_cpu_default="MASK_ABICALLS" + tm_defines="${tm_defines} TARGET_ABICALLS_DEFAULT=1" tm_file="mips/mips.h openbsd.h mips/openbsd.h mips/sdb.h" case ${target} in mips*el-*-openbsd*)
config/mips/linux.h +5 -7
@@ -37,10 +37,6 @@ along with GCC; see the file COPYING3.#undef MD_EXEC_PREFIX#undef MD_STARTFILE_PREFIX -/* If we don't set MASK_ABICALLS, we can't default to PIC. */ -#undef TARGET_DEFAULT -#define TARGET_DEFAULT MASK_ABICALLS -#define TARGET_OS_CPP_BUILTINS () \ do { \ LINUX_TARGET_OS_CPP_BUILTINS(); \
@@ -79,7 +75,8 @@ along with GCC; see the file COPYING3. %{static:-static}}}"#undef SUBTARGET_ASM_SPEC -#define SUBTARGET_ASM_SPEC "%{mabi=64: -64} %{!mno-abicalls:-KPIC}" +#define SUBTARGET_ASM_SPEC \ + "%{mabi=64: -64} %{mabicalls:%{fpic|fPIC:-KPIC;:-mnon-pic-abicalls}}"/* The MIPS assembler has different syntax for .set. We set it to .dummy to trap any errors. */
@@ -163,7 +160,8 @@ extern const char *host_detect_local_cpu# define MARCH_MTUNE_NATIVE_SPECS ""#endif -#define BASE_DRIVER_SELF_SPECS \ +#define LINUX_DRIVER_SELF_SPECS \ NO_SHARED_SPECS \ MARCH_MTUNE_NATIVE_SPECS -#define DRIVER_SELF_SPECS BASE_DRIVER_SELF_SPECS +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS LINUX_DRIVER_SELF_SPECS
config/mips/elfoabi.h +2 -1
@@ -19,7 +19,8 @@ You should have received a copy of the G along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#define DRIVER_SELF_SPECS \ +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS \/* Make sure a -mips option is present. This helps us to pick \ the right multilib, and also makes the later specs easier \ to write. */ \
config/mips/linux64.h +3 -3
@@ -20,9 +20,9 @@ along with GCC; see the file COPYING3./* Force the default endianness and ABI flags onto the command line in order to make the other specs easier to write. */ -#undef DRIVER_SELF_SPECS -#define DRIVER_SELF_SPECS \ -BASE_DRIVER_SELF_SPECS \ +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS \ +LINUX_DRIVER_SELF_SPECS \ " %{!EB:%{!EL:%(endian_spec)}}" \ " %{!mabi=*: -mabi=n32}"
config/mips/sde.h +2 -1
@@ -19,7 +19,8 @@ You should have received a copy of the G along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#define DRIVER_SELF_SPECS \ +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS \/* Make sure a -mips option is present. This helps us to pick \ the right multilib, and also makes the later specs easier \ to write. */ \
config/mips/mips.md +19 -2
@@ -4462,6 +4462,22 @@ [(set (match_operand:P 0 "register_operand" "=d") (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))]) +;; Move the constant value of __gnu_local_gp (operand 1) into +;; operand 0, for non-PIC abicalls code. All uses of the result +;; are explicit, so there's no need for unspec_volatile here. +(define_insn_and_split "loadgp_nonpic_<mode>" + [(set (match_operand:P 0 "register_operand" "=d") + (const:P (unspec:P [(match_operand 1 "" "")] UNSPEC_LOADGP)))] + "TARGET_NONPIC_ABICALLS" + "#" + "" + [(const_int 0)] +{ + mips_emit_move (operands[0], operands[1]); + DONE; +} + [(set_attr "length" "8")]) + ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset ;; of _gp from the start of this function. Operand 1 is the incoming ;; function address.
@@ -5827,11 +5843,12 @@ ;; Restore the gp that we saved above. Despite the earlier comment, it seems ;; that older code did recalculate the gp from $25. Continue to jump through -;; $25 for compatibility (we lose nothing by doing so). +;; $25 for compatibility (we lose nothing by doing so). Similarly restore +;; $gp if we might be jumping to code which expects that. (define_expand "builtin_longjmp" [(use (match_operand 0 "register_operand"))] - "TARGET_USE_GOT" + "TARGET_USE_GOT || TARGET_ABICALLS" { /* The elements of the buffer are, in order: */ int W = GET_MODE_SIZE (Pmode);
config/mips/iris6.h +2 -1
@@ -29,7 +29,8 @@ along with GCC; see the file COPYING3./* Force the default ABI onto the command line in order to make the specs easier to write. Default to the mips2 ISA for the O32 ABI. */ -#define DRIVER_SELF_SPECS \ +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS \ "%{!mabi=*: -mabi=n32}", \ "%{mabi=32: %{!mips*: %{!march*: -mips2}}}"
config/mips/mips.c +80 -39
255 lines not on this page · raw message
config/mips/mips.h +57 -7
102 lines not on this page · raw message
config/mips/vr.h +2 -1
@@ -26,7 +26,8 @@ along with GCC; see the file COPYING3.MULTILIB_ABI_DEFAULT , \ DEFAULT_VR_ARCH } -#define DRIVER_SELF_SPECS \ +#undef SUBTARGET_SELF_SPECS +#define SUBTARGET_SELF_SPECS \/* Enforce the default architecture. This is mostly for \ the assembler's benefit. */ \ "%{!march=*:%{!mfix-vr4120:%{!mfix-vr4130:" \
2008-03-07 Daniel Jacobowitz <[email protected]>
gdb/
* mips-tdep.c (mips32_scan_prologue): Stop scanning at branches.
2008-03-10 Daniel Jacobowitz <[email protected]>
gdb/
* mips-linux-tdep.c (mips_linux_in_dynsym_resolve_code): Update comments.
(mips_linux_skip_resolver): Also use glibc_skip_solib_resolver. (mips_linux_init_abi): Do not override skip_trampoline_code.
* configure.tgt (mips*-*-linux*): Add glibc-tdep.o.
* mips-tdep.c (mips_stub_frame_sniffer): Use the stub frame sniffer for .MIPS.pic_stubs. (mips_skip_mips16_trampoline_code): Rename from mips_skip_trampoline_code. (mips_skip_pic_trampoline_code, mips_skip_trampoline_code): New.
* infrun.c (handle_inferior_event): Do not check IN_SOLIB_DYNSYM_RESOLVE_CODE. Do not pass zero to in_solib_dynsym_resolve_code.
* Makefile.in (mips-linux-tdep.o): Update.
Index: gdb/Makefile.in
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/Makefile.in,v retrieving revision 1.1027
Makefile.in +1 -1
@@ -2519,7 +2519,7 @@ mips-linux-tdep.o: mips-linux-tdep.c $(d $(gdb_assert_h) $(frame_h) $(regcache_h) $(trad_frame_h) \ $(tramp_frame_h) $(gdbtypes_h) $(solib_h) $(symtab_h) \ $(mips_linux_tdep_h) $(solist_h) $(solib_svr4_h) \ - $(target_descriptions_h) + $(target_descriptions_h) $(glibc_tdep_h) mipsnbsd-nat.o: mipsnbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) \ $(target_h) $(mips_tdep_h) $(mipsnbsd_tdep_h) $(inf_ptrace_h) mipsnbsd-tdep.o: mipsnbsd-tdep.c $(defs_h) $(gdbcore_h) $(regcache_h) \
Index: gdb/configure.tgt
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/configure.tgt,v retrieving revision 1.203
configure.tgt +1 -1
@@ -297,7 +297,7 @@ mips*-sgi-irix6*) ;; mips*-*-linux*) # Target: Linux/MIPS - gdb_target_obs="mips-tdep.o mips-linux-tdep.o \ + gdb_target_obs="mips-tdep.o mips-linux-tdep.o glibc-tdep.o \ corelow.o solib.o solib-svr4.o symfile-mem.o" gdb_sim=../sim/mips/libsim.a build_gdbserver=yes
Index: gdb/infrun.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/infrun.c,v retrieving revision 1.282
infrun.c +2 -13
@@ -2863,12 +2863,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (until we exit the run time loader code and reach the callee's address. */ if (step_over_calls ==STEP_OVER_UNDEBUGGABLE -#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE - &&IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc) -#else - &&in_solib_dynsym_resolve_code (stop_pc) -#endif - ) + &&in_solib_dynsym_resolve_code (stop_pc)) {CORE_ADDR pc_after_resolver =gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
@@ -2961,13 +2956,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (if (real_stop_pc !=0 ) ecs->stop_func_start = real_stop_pc; - if ( -#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE - IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start) -#else - in_solib_dynsym_resolve_code (ecs->stop_func_start) -#endif -) +if (real_stop_pc !=0 &&in_solib_dynsym_resolve_code (real_stop_pc)) {struct symtab_and_line sr_sal;init_sal (&sr_sal);
Index: gdb/mips-linux-tdep.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/mips-linux-tdep.c,v retrieving revision 1.71
mips-linux-tdep.c +6 -6
@@ -37,6 +37,7 @@#include "symtab.h" #include "target-descriptions.h" #include "mips-linux-tdep.h" +#include "glibc-tdep.h" static struct target_so_ops mips_svr4_so_ops;
@@ -666,13 +667,13 @@ mips_linux_in_dynsym_stub (CORE_ADDR pc, }/* Return non-zero iff PC belongs to the dynamic linker resolution -code or to a stub. */ +code, a PLT entry, or a lazy binding stub. */ static int mips_linux_in_dynsym_resolve_code (CORE_ADDR pc) {/* Check whether PC is in the dynamic linker. This also checks -whether it is in the .plt section, which MIPS does not use. */ +whether it is in the .plt section, used by non-PIC executables. */ if (svr4_in_dynsym_resolve_code (pc))return 1 ;
@@ -688,8 +689,8 @@ mips_linux_in_dynsym_resolve_code (CORE_and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc implementation of this triggers at "fixup" from the same objfile as "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at -"__dl_runtime_resolve" directly. An unresolved PLT entry will -point to _dl_runtime_resolve, which will first call +"__dl_runtime_resolve" directly. An unresolved lazy binding +stub will point to _dl_runtime_resolve, which will first call __dl_runtime_resolve, and then pass control to the resolved function. */
@@ -703,7 +704,7 @@ mips_linux_skip_resolver (struct gdbarchif (resolver &&SYMBOL_VALUE_ADDRESS (resolver) == pc)return frame_pc_unwind (get_current_frame ()); -return 0 ; +return glibc_skip_solib_resolver (gdbarch, pc); }/* Signal trampoline support. There are four supported layouts for a
@@ -1151,7 +1152,6 @@ mips_linux_init_abi (struct gdbarch_infobreak ; } -set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
Index: gdb/mips-tdep.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/mips-tdep.c,v retrieving revision 1.475
mips-tdep.c +81 -1
113 lines not on this page · raw message
2008-06-27 Daniel Jacobowitz <[email protected]>
* longlong.h: Update from GCC.
Index: stdlib/longlong.h
===================================================================
RCS file: /cvs/glibc/libc/stdlib/longlong.h,v
retrieving revision 1.31
longlong.h +132 -25
241 lines not on this page · raw message
2008-03-28 Mark Shinwell <[email protected]>
Daniel Jacobowitz <[email protected]>
* sysdeps/mips/dl-lookup.c: New.
* sysdeps/mips/do-lookup.h: New.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_NO_PLT): Remove definition.
(ELF_MACHINE_JMP_SLOT): Alter definition and update comment. (elf_machine_type_class): Likewise. (ELF_MACHINE_PLT_REL): Define. (elf_machine_fixup_plt): New. (elf_machine_plt_value): New. (elf_machine_reloc): Handle jump slot and copy relocations. (elf_machine_lazy_rel): Point relocation place at PLT if required.
(elf_machine_runtime_setup): Fill in .got.plt header.
* sysdeps/mips/dl-trampoline.c: New.
* sysdeps/mips/bits/linkmap.h (link_map_machine): New.
* sysdeps/mips/tls-macros.h: Load $gp as required.
* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (SYSCALL_ERROR_LABEL):
Delete definition.
* sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h (PSEUDO_CPLOAD, PSEUDO_ERRJMP, PSEUDO_SAVEGP, PSEUDO_LOADGP): Define. (PSEUDO): Use them. Move outside __PIC__.
(PSEUDO_JMP): New.
(CENABLE, CDISABLE): Use it.
unix/sysv/linux/mips/mips32/sysdep.h +1 -9
@@ -35,15 +35,7 @@ # define SYS_ify(syscall_name) __NR_/**/syscall_name#endif -#ifdef __ASSEMBLER__ - -/* We don't want the label for the error handler to be visible in the symbol -table when we define it here. */ -#ifdef __PIC__ -# define SYSCALL_ERROR_LABEL 99b -#endif - -#else /* ! __ASSEMBLER__ */ +#ifndef __ASSEMBLER__/* Define a macro which expands into the inline wrapper code for a system call. */
unix/sysv/linux/mips/nptl/sysdep-cancel.h +33 -20
117 lines not on this page · raw message
mips/do-lookup.h +37 -0
@@ -0,0 +1,37 @@ +/* MIPS-specific veneer to GLIBC's do-lookup.h. +Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +/* The semantics of zero/non-zero values of undefined symbols differs +depending on whether the non-PIC ABI is in use. Under the non-PIC ABI, +a non-zero value indicates that there is an address reference to the +symbol and thus it must always be resolved (except when resolving a jump +slot relocation) to the PLT entry whose address is provided as the +symbol's value; a zero value indicates that this canonical-address +behaviour is not required. Yet under the classic MIPS psABI, a zero value +indicates that there is an address reference to the function and the +dynamic linker must resolve the symbol immediately upon loading. To +avoid conflict, symbols for which the dynamic linker must assume the +non-PIC ABI semantics are marked with the STO_MIPS_PLT flag. The +following ugly hack causes the code in the platform-independent +do-lookup.h file to check this flag correctly. */ +#define st_value st_shndx == SHN_UNDEF && !(sym->st_other & STO_MIPS_PLT)) \ + || (sym->st_value +#include_next "do-lookup.h" +#undef st_value +
mips/tls-macros.h +26 -18
72 lines not on this page · raw message
mips/dl-machine.h +121 -8
172 lines not on this page · raw message
mips/dl-lookup.c +581 -0
581 lines not on this page · raw message
mips/dl-trampoline.c +41 -0
44 lines not on this page · raw message
mips/bits/linkmap.h +4 -0
@@ -0,0 +1,4 @@ +struct link_map_machine + { +Elf32_Addr plt;/* Address of .plt */ + };
2008-03-14 Mark Shinwell <[email protected]>
* elf/elf.h (STO_MIPS_PLT): New. (R_MIPS_COPY): New. (R_MIPS_JUMP_SLOT): New. (R_MIPS_NUM): Redefine to 128. (DT_MIPS_PLTGOT): New. (DT_MIPS_RWPLT): New. (DT_MIPS_NUM): Redefine to 0x35.
elf.h +11 -2
@@ -1395,6 +1395,7 @@ typedef struct#define STO_MIPS_INTERNAL 0x1#define STO_MIPS_HIDDEN 0x2#define STO_MIPS_PROTECTED 0x3 +#define STO_MIPS_PLT 0x8#define STO_MIPS_SC_ALIGN_UNUSED 0xff/* MIPS specific values for `st_info'. */
@@ -1541,8 +1542,10 @@ typedef struct#define R_MIPS_TLS_TPREL_HI16 49/* TP-relative offset, high 16 bits */ #define R_MIPS_TLS_TPREL_LO16 50/* TP-relative offset, low 16 bits */ #define R_MIPS_GLOB_DAT 51 +#define R_MIPS_COPY 126 +#define R_MIPS_JUMP_SLOT 127/* Keep this the last entry. */ -#define R_MIPS_NUM 52 +#define R_MIPS_NUM 128/* Legal values for p_type field of Elf32_Phdr. */
@@ -1608,7 +1611,13 @@ typedef struct#define DT_MIPS_COMPACT_SIZE 0x7000002f/* (O32)Size of compact rel section. */ #define DT_MIPS_GP_VALUE 0x70000030/* GP value for aux GOTs. */ #define DT_MIPS_AUX_DYNAMIC 0x70000031/* Address of aux .dynamic. */ -#define DT_MIPS_NUM 0x32 +/* The address of .got.plt in an executable using the new non-PIC ABI. */ +#define DT_MIPS_PLTGOT 0x70000032 +/* The base of the PLT in an executable using the new non-PIC ABI if that +PLT is writable. For a non-writable PLT, this is omitted or has a zero +value. */ +#define DT_MIPS_RWPLT 0x70000034 +#define DT_MIPS_NUM 0x35/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
? changelog-diffs
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.446
bfd-in2.h +1 -1
@@ -2661,7 +2661,7 @@ to compensate for the borrow when the loBFD_RELOC_MIPS_TLS_TPREL_LO16 , -/* MIPS ELF relocations (VxWorks extensions). */ +/* MIPS ELF relocations (VxWorks and nonpic extensions). */ BFD_RELOC_MIPS_COPY , BFD_RELOC_MIPS_JUMP_SLOT,
Index: bfd/elf32-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-mips.c,v
retrieving revision 1.197
elf32-mips.c +56 -94
216 lines not on this page · raw message
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.304
elflink.c +1 -1
@@ -1178,7 +1178,7 @@ _bfd_elf_merge_symbol (bfd *abfd,if (olddef && newdyn) oldweak = FALSE; -/* Allow changes between different types of funciton symbol. */ +/* Allow changes between different types of function symbol. */ if (bed->is_function_type (ELF_ST_TYPE (sym->st_info)) && bed->is_function_type (h->type)) *type_change_ok = TRUE;
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.230
elfxx-mips.c +871 -140
203 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Index: bfd/elfxx-mips.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.h,v
retrieving revision 1.38
The rest of this diff is not shown. View the raw message.
Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.174
The rest of this diff is not shown. View the raw message.
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.411
The rest of this diff is not shown. View the raw message.
Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.388
The rest of this diff is not shown. View the raw message.
Index: include/elf/mips.h
===================================================================
RCS file: /cvs/src/src/include/elf/mips.h,v
retrieving revision 1.37
The rest of this diff is not shown. View the raw message.
Index: ld/emulparams/elf32bmip.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32bmip.sh,v retrieving revision 1.16
The rest of this diff is not shown. View the raw message.
Index: ld/emulparams/elf32ebmipvxworks.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32ebmipvxworks.sh,v retrieving revision 1.2
The rest of this diff is not shown. View the raw message.
Index: ld/emulparams/elf32elmipvxworks.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32elmipvxworks.sh,v retrieving revision 1.1
The rest of this diff is not shown. View the raw message.
Index: ld/emultempl/mipself.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/mipself.em,v
retrieving revision 1.9
The rest of this diff is not shown. View the raw message.
Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.85
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 2 lines · Daniel Jacobowitz
We've shipped our version. Richard's version has presumably also shipped.
Right.
Quoted 9 lines
We did negotiate the ABI changes with MTI; this is not quite as good as doing it in full view, but it was the best we could manage and MTI is as close to a central authority for the MIPS psABI as exists today.
Richard, what are your thoughts on reconciling the differences? You can surely guess that I want to avoid changing our ABI now, even for relatively significant technical reasons - I'm all ears if there's a major reason, but in the comparisons I do not see one.
I suppose I still support the trade-off between the 5-insn MIPS I stubs (with extra-long variation for large PLT indices) and the absolute .got.plt address I used. And I still think it's shame we're treating STO_MIPS_PLT and STO_MIPS16 as separate; we then only have 1 bit of st_other unclaimed.
However, IMO, your argument about MTI being the central authority is a killer one. The purpose of the GNU tools should be to follow appropriate standards where applicable (and extend them where it seems wise). So from that point of view, I agree that the GNU tools should follow the ABI that Nigel and MTI set down. Consider my patch withdrawn.
TBH, the close relationship between CodeSourcery and MTI make it difficult for a non-Sourcerer and non-MTI employee to continue to be a MIPS maintainer. I won't be in-the-know about this sort of thing.
I've been thinking about that a lot recently, since I heard about your implementation. I kind-of guessed it had been agreed with MTI beforehand (although I hadn't realised MTI themselves had written the specification). Having thought it over, I think it would be best if I stand down as a MIPS maintainer and if someone with the appropriate commercial connections is appointed instead. I'd recommend any combination of yourself, Adam Nemet and David Daney (subject to said people being willing, of course).
Richard
Quoted 8 lines · Richard Sandiford
I've been thinking about that a lot recently, since I heard about your implementation. I kind-of guessed it had been agreed with MTI beforehand (although I hadn't realised MTI themselves had written the specification). Having thought it over, I think it would be best if I stand down as a MIPS maintainer and if someone with the appropriate commercial connections is appointed instead. I'd recommend any combination of yourself, Adam Nemet and David Daney (subject to said people being willing, of course).
I realised afterwards that this might be offensive by who it left out. For the record, it wasn't supposed to be an exclusive list. Other people have strong claims too. ;)
Richard
Quoted 6 lines · Richard Sandiford
However, IMO, your argument about MTI being the central authority is a killer one. The purpose of the GNU tools should be to follow appropriate standards where applicable (and extend them where it seems wise). So from that point of view, I agree that the GNU tools should follow the ABI that Nigel and MTI set down. Consider my patch withdrawn.
While I'm not entirely clear how this decision came about I'd like to point out that it is unfortunate that MTI had not sought wider consensus for this ABI extension among MIPS implementors and the community.
We would not be in this situation with duplicated efforts and much frustration if this proposal had been circulated properly ahead of time.
Quoted 8 lines
I've been thinking about that a lot recently, since I heard about your implementation. I kind-of guessed it had been agreed with MTI beforehand (although I hadn't realised MTI themselves had written the specification). Having thought it over, I think it would be best if I stand down as a MIPS maintainer and if someone with the appropriate commercial connections is appointed instead. I'd recommend any combination of yourself, Adam Nemet and David Daney (subject to said people being willing, of course).
Richard, while I understand your frustration I really hope that you will reconsider your decision and remain the MIPS maintainer. I think there is a chance that if the community expresses that MTI should seek broader consensus for such proposals they will do so in the future.
Your expertise as the GCC maintainer has improved the backend tremendously and and you should be given all the information necessary to continue your great work.
Adam
Quoted 34 lines · Richard Sandiford
Quoted 2 lines · Daniel Jacobowitz
We've shipped our version. Richard's version has presumably also shipped.
Right.
Quoted 9 lines
We did negotiate the ABI changes with MTI; this is not quite as good as doing it in full view, but it was the best we could manage and MTI is as close to a central authority for the MIPS psABI as exists today.
Richard, what are your thoughts on reconciling the differences? You can surely guess that I want to avoid changing our ABI now, even for relatively significant technical reasons - I'm all ears if there's a major reason, but in the comparisons I do not see one.
I suppose I still support the trade-off between the 5-insn MIPS I stubs (with extra-long variation for large PLT indices) and the absolute .got.plt address I used. And I still think it's shame we're treating
STO_MIPS_PLTandSTO_MIPS16as separate; we then only have 1 bit ofst_otherunclaimed.However, IMO, your argument about MTI being the central authority is a killer one. The purpose of the GNU tools should be to follow appropriate standards where applicable (and extend them where it seems wise). So from that point of view, I agree that the GNU tools should follow the ABI that Nigel and MTI set down. Consider my patch withdrawn.
TBH, the close relationship between CodeSourcery and MTI make it difficult for a non-Sourcerer and non-MTI employee to continue to be a MIPS maintainer. I won't be in-the-know about this sort of thing.
Quoted 4 lines
I've been thinking about that a lot recently, since I heard about your implementation. I kind-of guessed it had been agreed with MTI beforehand (although I hadn't realised MTI themselves had written the specification).
The specification is a co-production of MTI and CS. I believe the reason why it wasn't discussed in a wider audience is that it occured to nobody there could be a parallel effort going on after all those years!
Quoted 5 lines
Having thought it over, I think it would be best
if I stand down as a MIPS maintainer and if someone with the appropriate commercial connections is appointed instead. I'd recommend any combination of yourself, Adam Nemet and David Daney (subject to said people being willing, of course).
FWIW, I believe a person who is _not_ in the midst of the commercial pressures adds valuable perspective as a maintainer.
Thiemo
Quoted 5 lines · Richard Sandiford
I suppose I still support the trade-off between the 5-insn MIPS I stubs (with extra-long variation for large PLT indices) and the absolute .got.plt address I used. And I still think it's shame we're treating
STO_MIPS_PLTandSTO_MIPS16as separate; we then only have 1 bit ofst_otherunclaimed.
I'm undecided about the MIPS I issue, but I completely agree about STO_MIPS16/STO_MIPS_PLT. I wish we'd thought of that too. At least our implementation didn't have STO_MIPS_PIC; so there's one bit left, and assuming we add support for ld -r (likely) we can do it your way.
For the final merged versions of these patches, even if they implement "our" version, I hope to draw heavily on your work. It's always high quality and the GOT cleanups in particular look very useful.
Quoted 5 lines
TBH, the close relationship between CodeSourcery and MTI make it difficult for a non-Sourcerer and non-MTI employee to continue to be a MIPS maintainer. I won't be in-the-know about this sort of thing.
Quoted 8 lines
I've been thinking about that a lot recently, since I heard about your implementation. I kind-of guessed it had been agreed with MTI beforehand (although I hadn't realised MTI themselves had written the specification). Having thought it over, I think it would be best if I stand down as a MIPS maintainer and if someone with the appropriate commercial connections is appointed instead. I'd recommend any combination of yourself, Adam Nemet and David Daney (subject to said people being willing, of course).
I'm sorry you feel this way. I believe strongly that corporate affiliation is not a useful indicator for maintainership; the system we have set up here relies more on individual knowledge and experience than affiliation.
We could have done more to keep everyone informed of our progress; I could write an essay on why we didn't, but I'd rather not. We're talking internally about how to avoid this unfortunate coincidence in the future. Anyway, there's plenty of blame to go around.
I think you're doing an excellent job as a GCC maintainer, and so does everyone I spoke to about this at CS. If you no longer have the time or incentive to do it, I won't argue with you about stepping down, but please don't because of this incident.
[In any case, I'd decline; I'm trying to shed some of my existing maintenance responsibilities so that I can spend more time on the ones I care most about. Anyone else want to be binutils release manager?]
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
Thanks to everyone for their kind messages. I won't drag this out for non-MIPS folk by replying publicly to each one.
Quoted 1 line · Daniel Jacobowitz
the GOT cleanups in particular look very useful.
Thanks. To be clear: the withdrawal was simply for the patches in this message. Although the original motivation for the GOT cleanups was to reduce the amount of wasted space in mostly-non-PIC executables, they're really a separate change in their own right. My hope was that, even without the non-PIC stuff, the new code might be more maintainable than what we have now.
Quoted 4 lines
We could have done more to keep everyone informed of our progress; I could write an essay on why we didn't, but I'd rather not. We're talking internally about how to avoid this unfortunate coincidence in the future. Anyway, there's plenty of blame to go around.
FWIW, I don't blame MTI or CS at all for this. Duplicated effort is part of the risk one runs with the model that both you (CS) and I were following. (And for the record, I say "I" because the fault was mine rather than Specifix's.)
When I was doing the work, I was expecting to use the patches as the basis for a discussion on this list. And I honestly expected to have to change some of the details as a result. E.g. I wasn't sure what the reaction would be to requiring MIPS II or above. So it's no surprise that my version as posted is not going to be used.
And when I learnt about your alternative implementation, I was expecting some of that implementation to be chosen instead. The difficulty was simply that, as you rightly said, MTI are the authority here. That made any discussion on this list moot.
That was just an attempt to clarify things rather than force you into writing an essay ;)
Anyway, enough of that. Back to technical stuff. Would it work if we had stubs like this:
lui t7,%hi(.got.plt entry)
lw t9,%lo(.got.plt entry)(t7)
addiu t8,t7,%lo(.got.plt entry)
jr t9 ...
lui t7,%hi(.got.plt entry + 4) [next entry]
and a header like this:
lui gp,%hi(.got.plt)
lw t9,%lo(.got.plt)(gp)
addiu gp,gp,%lo(.got.plt)
subu t8,t8,gp
move t7,ra
srl t8,t8,2
jalr t9
subu t8,t8,2(Key for my benefit, 'cos I can only think in terms of numerical registers:
t7 = $15
t8 = $24
t9 = $25)The size of the header and first 0x10000 stubs would be the same. I think it would also preserve the resolver interface while removing the need for the extra-large .plts. The only incompatibility I can see would be that objdump on older executables would not get the foo@plt symbols right for large indices.
OTOH, perhaps you could argue that the extra complication of the two PLT entries doesn't count for much given that the code is already written. It's just an idea.
Richard
Quoted 9 lines · Richard Sandiford
The size of the header and first
0x10000stubs would be the same. I think it would also preserve the resolver interface while removing the need for the extra-large .plts. The only incompatibility I can see would be that objdump on older executables would not get the foo@plt symbols right for large indices.OTOH, perhaps you could argue that the extra complication of the two PLT entries doesn't count for much given that the code is already written. It's just an idea.
Your version looks fine to me, it's ABI-preserving, the PLT entries still work for MIPS I and still have the same runtime cost when not resolving. I like it - thanks!
I'm not worried about making people upgrade objdump, either.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
Quoted 2 lines · Richard Sandiford
I suppose the good news is that we can pick the best bits of each implementation as the official one.
And that's what I've been working on. We had to pick some bits from the CodeSourcery implementation that I wouldn't describe as "best" - arbitrarily different or a bit less efficient - due to ABI constraints we've already discussed. But I was able to pick up clever bits from both sets as I combined them.
I have attached patch for gdb and glibc. These are only slightly changed from my last posting. I've also attached quilt series for binutils and gcc; these are based on Richard's. I disabled a couple of patches that had already been applied to binutils HEAD, but otherwise did not change any of Richard's patches. I added a cs-plts.patch to the end of both series. This form is probably better for review and discussion than it would be for committing; the bits from cs-plts.patch belong in several earlier patches in each series, but I decided this would be an unworkable way to compare patches.
I have tested this thoroughly on mips-linux and somewhat on N32 / N64 (binutils testsuites and GCC's builtins.exp). The testing was before some last minute fixes, though, and I've only retested individual tests since. I'll be rerunning a complete test cycle, but I wanted to get this posted and I'm 99% sure I didn't break anything (this time).
All comments welcome - Richard, especially from you. How would you like to proceed? I think the first step should be to get your other binutils/gcc patches merged, including MIPS16 PIC; I used those as a base. But see a few of the notes for potential problems with those patches.
My notes about the merge:
- Richard's ld -r support is an addition to the ABI, but does not conflict with anything else, so I included it. I discovered two potential problems:
- If a symbol with STO_MIPS_PIC is localized using objcopy, binutils will ignore the flag. I don't think this is presently worth implementing but it might be wise to add an error message. I haven't done that yet.
- Superfluous la25 stubs are suppressed when a PIC2 file uses jal. This is an optimization performed by gcc -mno-shared. It will not work after ld -r into a non-PIC file; the jump will appear to come from a non-PIC object and be redirected to a new stub. This is only a minor performance pessimization and I do not plan to fix it.
- Some mips16 call stubs called through $1 instead of $25. I believe I've fixed them all, though I am not set up to test mips16. I don't think this would have caused a problem, since as far as I can tell the indirect jumps are only used when the target is mips16; but better safe than sorry so we now follow the ABI.
- It would be nice to generate, in some cases, both a .MIPS.stubs lazy binding stub and a PLT entry. However, I determined that considerable additional work would be required to do this; most likely we'd need two entries for the same symbol in the dynamic symbol table so that the GOT entry could be associated with the lazy loading stub. As things stand it is possible to link non-PIC and PIC code together, and if both call the same function and the non-PIC code takes its address, calls to the function from PIC code will be penalized. I do not expect this case to matter. Most applications will be predominantly PIC or non-PIC.
- I've dropped support for a non-fixed $gp. This is a handy optimization, but it was getting in the way and it was the part of the GCC patch Richard had the most comments on. I can resubmit it after everything else is merged.
- Richard's implementation had __PIC__ mean abicalls. Our patch changed __PIC__ to mean pic2 abicalls only. I've included that in this patch. My reasoning is that most non-pic non-abicalls code works properly even with pic0 abicalls; the only problem is indirect calls through a register other than $25. This lets glibc automatically use some more efficient sequences in static applications.
- With Richard's patches I saw a crash building libstdc++ with symbol versioning. This was caused by not following indirect symbols in all cases during check_relocs; we would assign a GGA_NORMAL GOT slot to an indirect symbol, and trigger an assertion failure while removing it. This is sensitive to link order.
- A small change in glibc fixes the canonical address of functions with PLT entries, when referenced from PIC code.
- I added pointer_equality_needed support to binutils to suppress setting st_value to the PLT entry in most cases.
- The GCC new-static-chain.patch causes nested-func-4.exe to fail. _mcount is called through a PLT entry, which clobbers $15. I believe we need to add this to MIPS_SAVE_REG_FOR_PROFILING_P. I didn't fix this yet.
- no-fn-name-already-declared.patch removed the call to ASM_OUTPUT_TYPE_DIRECTIVE for Linux. .ent has similar effect, but is suppressed by flag_inhibit_size_directive. This caused glibc's _init to be STT_OBJECT, and not get a PIC call stub. I've changed GCC to emit .type for all platforms; Richard, if this should be restricted to the status quo (i.e. Linux) let me know. Also the STT_FUNC check in the linker was unnecessary now that we only use la25 stubs for jump relocations.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
2008-03-07 Daniel Jacobowitz <[email protected]>
gdb/
* mips-tdep.c (mips32_scan_prologue): Stop scanning at branches.
2008-07-24 Daniel Jacobowitz <[email protected]>
gdb/
* mips-linux-tdep.c (mips_linux_in_dynsym_resolve_code): Update comments.
(mips_linux_skip_resolver): Also use glibc_skip_solib_resolver. (mips_linux_init_abi): Do not override skip_trampoline_code.
* configure.tgt (mips*-*-linux*): Add glibc-tdep.o.
* mips-tdep.c (mips_stub_frame_sniffer): Use the stub frame sniffer for PIC stubs.
(mips_skip_mips16_trampoline_code): Rename from mips_skip_trampoline_code. (mips_skip_pic_trampoline_code, mips_skip_trampoline_code): New.
* infrun.c (handle_inferior_event): Do not check IN_SOLIB_DYNSYM_RESOLVE_CODE. Do not pass zero to in_solib_dynsym_resolve_code.
* Makefile.in (mips-linux-tdep.o): Update.
2008-07-24 Daniel Jacobowitz <[email protected]>
gdb/gdbserver/
* configure.srv: Combine mips*64*-*-linux* and mips*-*-linux*.
Index: gdb/Makefile.in
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/Makefile.in,v retrieving revision 1.1027
Makefile.in +1 -1
@@ -2519,7 +2519,7 @@ mips-linux-tdep.o: mips-linux-tdep.c $(d $(gdb_assert_h) $(frame_h) $(regcache_h) $(trad_frame_h) \ $(tramp_frame_h) $(gdbtypes_h) $(solib_h) $(symtab_h) \ $(mips_linux_tdep_h) $(solist_h) $(solib_svr4_h) \ - $(target_descriptions_h) + $(target_descriptions_h) $(glibc_tdep_h) mipsnbsd-nat.o: mipsnbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) \ $(target_h) $(mips_tdep_h) $(mipsnbsd_tdep_h) $(inf_ptrace_h) mipsnbsd-tdep.o: mipsnbsd-tdep.c $(defs_h) $(gdbcore_h) $(regcache_h) \
Index: gdb/configure.tgt
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/configure.tgt,v retrieving revision 1.203
configure.tgt +1 -1
@@ -297,7 +297,7 @@ mips*-sgi-irix6*) ;; mips*-*-linux*) # Target: Linux/MIPS - gdb_target_obs="mips-tdep.o mips-linux-tdep.o \ + gdb_target_obs="mips-tdep.o mips-linux-tdep.o glibc-tdep.o \ corelow.o solib.o solib-svr4.o symfile-mem.o" gdb_sim=../sim/mips/libsim.a build_gdbserver=yes
Index: gdb/infrun.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/infrun.c,v retrieving revision 1.282
infrun.c +2 -13
@@ -2863,12 +2863,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (until we exit the run time loader code and reach the callee's address. */ if (step_over_calls ==STEP_OVER_UNDEBUGGABLE -#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE - &&IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc) -#else - &&in_solib_dynsym_resolve_code (stop_pc) -#endif - ) + &&in_solib_dynsym_resolve_code (stop_pc)) {CORE_ADDR pc_after_resolver =gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
@@ -2961,13 +2956,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (if (real_stop_pc !=0 ) ecs->stop_func_start = real_stop_pc; - if ( -#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE - IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start) -#else - in_solib_dynsym_resolve_code (ecs->stop_func_start) -#endif -) +if (real_stop_pc !=0 &&in_solib_dynsym_resolve_code (real_stop_pc)) {struct symtab_and_line sr_sal;init_sal (&sr_sal);
Index: gdb/mips-linux-tdep.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/mips-linux-tdep.c,v retrieving revision 1.71
mips-linux-tdep.c +6 -6
@@ -37,6 +37,7 @@#include "symtab.h" #include "target-descriptions.h" #include "mips-linux-tdep.h" +#include "glibc-tdep.h" static struct target_so_ops mips_svr4_so_ops;
@@ -666,13 +667,13 @@ mips_linux_in_dynsym_stub (CORE_ADDR pc, }/* Return non-zero iff PC belongs to the dynamic linker resolution -code or to a stub. */ +code, a PLT entry, or a lazy binding stub. */ static int mips_linux_in_dynsym_resolve_code (CORE_ADDR pc) {/* Check whether PC is in the dynamic linker. This also checks -whether it is in the .plt section, which MIPS does not use. */ +whether it is in the .plt section, used by non-PIC executables. */ if (svr4_in_dynsym_resolve_code (pc))return 1 ;
@@ -688,8 +689,8 @@ mips_linux_in_dynsym_resolve_code (CORE_and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc implementation of this triggers at "fixup" from the same objfile as "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at -"__dl_runtime_resolve" directly. An unresolved PLT entry will -point to _dl_runtime_resolve, which will first call +"__dl_runtime_resolve" directly. An unresolved lazy binding +stub will point to _dl_runtime_resolve, which will first call __dl_runtime_resolve, and then pass control to the resolved function. */
@@ -703,7 +704,7 @@ mips_linux_skip_resolver (struct gdbarchif (resolver &&SYMBOL_VALUE_ADDRESS (resolver) == pc)return frame_pc_unwind (get_current_frame ()); -return 0 ; +return glibc_skip_solib_resolver (gdbarch, pc); }/* Signal trampoline support. There are four supported layouts for a
@@ -1151,7 +1152,6 @@ mips_linux_init_abi (struct gdbarch_infobreak ; } -set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
Index: gdb/mips-tdep.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/mips-tdep.c,v retrieving revision 1.475
mips-tdep.c +96 -1
134 lines not on this page · raw message
Index: gdb/gdbserver/configure.srv
===================================================================
RCS file: /scratch/gcc/repos/src/src/gdb/gdbserver/configure.srv,v retrieving revision 1.35
gdbserver/configure.srv +5 -12
@@ -86,22 +86,15 @@ case "${target}" in srv_linux_regsets=yes srv_linux_thread_db=yes ;; - mips*64*-*-linux*) srv_regobj=mips64-linux.o + mips*-*-linux*) srv_regobj="mips-linux.o mips64-linux.o" srv_tgtobj="linux-low.o linux-mips-low.o" - srv_xmlfiles="mips64-linux.xml" - srv_xmlfiles="${srv_xmlfiles} mips64-cpu.xml" - srv_xmlfiles="${srv_xmlfiles} mips64-cp0.xml" - srv_xmlfiles="${srv_xmlfiles} mips64-fpu.xml" - srv_linux_regsets=yes - srv_linux_usrregs=yes - srv_linux_thread_db=yes - ;; - mips*-*-linux*) srv_regobj=mips-linux.o - srv_tgtobj="linux-low.o linux-mips-low.o" - srv_xmlfiles="mips-linux.xml" + srv_xmlfiles="mips-linux.xml mips64-linux.xml" srv_xmlfiles="${srv_xmlfiles} mips-cpu.xml" srv_xmlfiles="${srv_xmlfiles} mips-cp0.xml" srv_xmlfiles="${srv_xmlfiles} mips-fpu.xml" + srv_xmlfiles="${srv_xmlfiles} mips64-cpu.xml" + srv_xmlfiles="${srv_xmlfiles} mips64-cp0.xml" + srv_xmlfiles="${srv_xmlfiles} mips64-fpu.xml" srv_linux_regsets=yes srv_linux_usrregs=yes srv_linux_thread_db=yes
2008-07-24 Mark Shinwell <[email protected]>
Daniel Jacobowitz <[email protected]> Richard Sandiford <[email protected]>
* sysdeps/mips/dl-lookup.c: New.
* sysdeps/mips/do-lookup.h: New.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_NO_PLT): Remove definition.
(ELF_MACHINE_JMP_SLOT): Alter definition and update comment. (elf_machine_type_class): Likewise. (ELF_MACHINE_PLT_REL): Define.
(elf_machine_fixup_plt): New.
(elf_machine_plt_value): New.
(elf_machine_reloc): Handle jump slot and copy relocations. (elf_machine_lazy_rel): Point relocation place at PLT if required.
(RESOLVE_GOTSYM): Take a relocation type argument. (elf_machine_got_rel): Bind lazy stubs directly to their target if !lazy. Skip lazy binding for PLT symbols. (elf_machine_runtime_setup): Fill in .got.plt header.
* sysdeps/mips/dl-trampoline.c (IFNEWABI): New macro. (_dl_runtime_pltresolve): New.
* sysdeps/mips/bits/linkmap.h: New file.
* sysdeps/mips/tls-macros.h: Load $gp as required. Merge 32-bit and 64-bit versions.
* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (SYSCALL_ERROR_LABEL):
Delete definition.
* sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h (PSEUDO_CPLOAD, PSEUDO_ERRJMP, PSEUDO_SAVEGP, PSEUDO_LOADGP): Define. (PSEUDO): Use them. Move outside __PIC__.
(PSEUDO_JMP): New.
(CENABLE, CDISABLE): Use it.
unix/sysv/linux/mips/mips32/sysdep.h +1 -9
@@ -35,15 +35,7 @@ # define SYS_ify(syscall_name) __NR_/**/syscall_name#endif -#ifdef __ASSEMBLER__ - -/* We don't want the label for the error handler to be visible in the symbol -table when we define it here. */ -#ifdef __PIC__ -# define SYSCALL_ERROR_LABEL 99b -#endif - -#else /* ! __ASSEMBLER__ */ +#ifndef __ASSEMBLER__/* Define a macro which expands into the inline wrapper code for a system call. */
unix/sysv/linux/mips/nptl/sysdep-cancel.h +33 -20
117 lines not on this page · raw message
mips/do-lookup.h +37 -0
@@ -0,0 +1,37 @@ +/* MIPS-specific veneer to GLIBC's do-lookup.h. +Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +/* The semantics of zero/non-zero values of undefined symbols differs +depending on whether the non-PIC ABI is in use. Under the non-PIC ABI, +a non-zero value indicates that there is an address reference to the +symbol and thus it must always be resolved (except when resolving a jump +slot relocation) to the PLT entry whose address is provided as the +symbol's value; a zero value indicates that this canonical-address +behaviour is not required. Yet under the classic MIPS psABI, a zero value +indicates that there is an address reference to the function and the +dynamic linker must resolve the symbol immediately upon loading. To +avoid conflict, symbols for which the dynamic linker must assume the +non-PIC ABI semantics are marked with the STO_MIPS_PLT flag. The +following ugly hack causes the code in the platform-independent +do-lookup.h file to check this flag correctly. */ +#define st_value st_shndx == SHN_UNDEF && !(sym->st_other & STO_MIPS_PLT)) \ + || (sym->st_value +#include_next "do-lookup.h" +#undef st_value +
mips/tls-macros.h +36 -60
122 lines not on this page · raw message
mips/dl-machine.h +141 -19
236 lines not on this page · raw message
mips/dl-lookup.c +581 -0
581 lines not on this page · raw message
mips/dl-trampoline.c +56 -0
71 lines not on this page · raw message
mips/bits/linkmap.h +4 -0
@@ -0,0 +1,4 @@ +struct link_map_machine + { +ElfW (Addr) plt;/* Address of .plt */ + };
2008-03-14 Mark Shinwell <[email protected]>
* elf/elf.h (STO_MIPS_PLT): New. (R_MIPS_COPY): New. (R_MIPS_JUMP_SLOT): New. (R_MIPS_NUM): Redefine to 128. (DT_MIPS_PLTGOT): New. (DT_MIPS_RWPLT): New. (DT_MIPS_NUM): Redefine to 0x35.
elf.h +11 -2
@@ -1395,6 +1395,7 @@ typedef struct#define STO_MIPS_INTERNAL 0x1#define STO_MIPS_HIDDEN 0x2#define STO_MIPS_PROTECTED 0x3 +#define STO_MIPS_PLT 0x8#define STO_MIPS_SC_ALIGN_UNUSED 0xff/* MIPS specific values for `st_info'. */
@@ -1541,8 +1542,10 @@ typedef struct#define R_MIPS_TLS_TPREL_HI16 49/* TP-relative offset, high 16 bits */ #define R_MIPS_TLS_TPREL_LO16 50/* TP-relative offset, low 16 bits */ #define R_MIPS_GLOB_DAT 51 +#define R_MIPS_COPY 126 +#define R_MIPS_JUMP_SLOT 127/* Keep this the last entry. */ -#define R_MIPS_NUM 52 +#define R_MIPS_NUM 128/* Legal values for p_type field of Elf32_Phdr. */
@@ -1608,7 +1611,13 @@ typedef struct#define DT_MIPS_COMPACT_SIZE 0x7000002f/* (O32)Size of compact rel section. */ #define DT_MIPS_GP_VALUE 0x70000030/* GP value for aux GOTs. */ #define DT_MIPS_AUX_DYNAMIC 0x70000031/* Address of aux .dynamic. */ -#define DT_MIPS_NUM 0x32 +/* The address of .got.plt in an executable using the new non-PIC ABI. */ +#define DT_MIPS_PLTGOT 0x70000032 +/* The base of the PLT in an executable using the new non-PIC ABI if that +PLT is writable. For a non-writable PLT, this is omitted or has a zero +value. */ +#define DT_MIPS_RWPLT 0x70000034 +#define DT_MIPS_NUM 0x35/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
2008-06-27 Daniel Jacobowitz <[email protected]>
* longlong.h: Update from GCC.
Index: stdlib/longlong.h
===================================================================
RCS file: /cvs/glibc/libc/stdlib/longlong.h,v
retrieving revision 1.31
longlong.h +132 -25
241 lines not on this page · raw message
Quoted 1 line · Daniel Jacobowitz
I have attached
Let's all pretend I attached this glibc patch, instead of the one in my previous message, please.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
2008-07-24 Mark Shinwell <[email protected]>
Daniel Jacobowitz <[email protected]> Richard Sandiford <[email protected]>
* sysdeps/mips/dl-lookup.c: New.
* sysdeps/mips/do-lookup.h: New.
* sysdeps/mips/dl-machine.h (ELF_MACHINE_NO_PLT): Remove definition.
(ELF_MACHINE_JMP_SLOT): Alter definition and update comment. (elf_machine_type_class): Likewise. (ELF_MACHINE_PLT_REL): Define.
(elf_machine_fixup_plt): New.
(elf_machine_plt_value): New.
(elf_machine_reloc): Handle jump slot and copy relocations. (elf_machine_lazy_rel): Point relocation place at PLT if required.
(RESOLVE_GOTSYM): Take a relocation type argument. (elf_machine_got_rel): Bind lazy stubs directly to their target if !lazy. Skip lazy binding for PLT symbols. (elf_machine_runtime_setup): Fill in .got.plt header.
* sysdeps/mips/dl-trampoline.c (IFNEWABI): New macro. (_dl_runtime_pltresolve): New.
* sysdeps/mips/bits/linkmap.h: New file.
* sysdeps/mips/tls-macros.h: Load $gp as required. Merge 32-bit and 64-bit versions.
* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (SYSCALL_ERROR_LABEL):
Delete definition.
* sysdeps/unix/sysv/linux/mips/nptl/sysdep-cancel.h (PSEUDO_CPLOAD, PSEUDO_ERRJMP, PSEUDO_SAVEGP, PSEUDO_LOADGP): Define. (PSEUDO): Use them. Move outside __PIC__.
(PSEUDO_JMP): New.
(CENABLE, CDISABLE): Use it.
unix/sysv/linux/mips/mips32/sysdep.h +1 -9
@@ -35,15 +35,7 @@ # define SYS_ify(syscall_name) __NR_/**/syscall_name#endif -#ifdef __ASSEMBLER__ - -/* We don't want the label for the error handler to be visible in the symbol -table when we define it here. */ -#ifdef __PIC__ -# define SYSCALL_ERROR_LABEL 99b -#endif - -#else /* ! __ASSEMBLER__ */ +#ifndef __ASSEMBLER__/* Define a macro which expands into the inline wrapper code for a system call. */
unix/sysv/linux/mips/nptl/sysdep-cancel.h +33 -20
117 lines not on this page · raw message
mips/do-lookup.h +37 -0
@@ -0,0 +1,37 @@ +/* MIPS-specific veneer to GLIBC's do-lookup.h. +Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +/* The semantics of zero/non-zero values of undefined symbols differs +depending on whether the non-PIC ABI is in use. Under the non-PIC ABI, +a non-zero value indicates that there is an address reference to the +symbol and thus it must always be resolved (except when resolving a jump +slot relocation) to the PLT entry whose address is provided as the +symbol's value; a zero value indicates that this canonical-address +behaviour is not required. Yet under the classic MIPS psABI, a zero value +indicates that there is an address reference to the function and the +dynamic linker must resolve the symbol immediately upon loading. To +avoid conflict, symbols for which the dynamic linker must assume the +non-PIC ABI semantics are marked with the STO_MIPS_PLT flag. The +following ugly hack causes the code in the platform-independent +do-lookup.h file to check this flag correctly. */ +#define st_value st_shndx == SHN_UNDEF && !(sym->st_other & STO_MIPS_PLT)) \ + || (sym->st_value +#include_next "do-lookup.h" +#undef st_value +
mips/tls-macros.h +36 -60
122 lines not on this page · raw message
mips/dl-machine.h +141 -19
236 lines not on this page · raw message
mips/dl-lookup.c +581 -0
581 lines not on this page · raw message
mips/dl-trampoline.c +55 -0
70 lines not on this page · raw message
mips/bits/linkmap.h +4 -0
@@ -0,0 +1,4 @@ +struct link_map_machine + { +ElfW (Addr) plt;/* Address of .plt */ + };
Quoted 9 lines · Daniel Jacobowitz
- Richard's ld -r support is an addition to the ABI, but does not conflict with anything else, so I included it. I discovered two potential problems:
- If a symbol with
STO_MIPS_PICis localized using objcopy, binutils will ignore the flag. I don't think this is presently worth implementing but it might be wise to add an error message. I haven't done that yet.
Quoted 5 lines
- Superfluous la25 stubs are suppressed when a PIC2 file uses jal. This is an optimization performed by gcc -mno-shared. It will not work after ld -r into a non-PIC file; the jump will appear to come from a non-PIC object and be redirected to a new stub. This is only a minor performance pessimization and I do not plan to fix it.
Yeah, for the record, this second one was actually a deliberate choice. There's no real object-level information to indicate -mno-sharedness (unlike "PIC"ness), so any attempt to recognise it would simply be a heuristic.
The ld -r support was really there for the same reason as the la $25
stubs: to allow "real" PIC and "new" non-PIC to be linked together. It seems unlikely that you'd have much -mno-shared code to link in if you're using a "new"-PIC-compatible sysroot.
Quoted 10 lines
- It would be nice to generate, in some cases, both a .MIPS.stubs lazy binding stub and a PLT entry. However, I determined that considerable additional work would be required to do this; most likely we'd need two entries for the same symbol in the dynamic symbol table so that the GOT entry could be associated with the lazy loading stub. As things stand it is possible to link non-PIC and PIC code together, and if both call the same function and the non-PIC code takes its address, calls to the function from PIC code will be penalized. I do not expect this case to matter. Most applications will be predominantly PIC or non-PIC.
Yeah, FWIW, I think we discussed this in the original three-way thread last year. (I think the original proposal was to use PLTs all the time for "new-PIC" executables. I remember arguing in favour of keeping .MIPS.stubs as an option because they're more efficient when handling the cases they can. I certainly agree that's it not worth trying to use both .MIPS.stubs and PLTs for the same function.)
Quoted 4 lines
- I've dropped support for a non-fixed $gp. This is a handy optimization, but it was getting in the way and it was the part of the GCC patch Richard had the most comments on. I can resubmit it after everything else is merged.
That's a shame. It was also the bit I liked best ;) What went wrong?
(My comments were only minor.)
Quoted 6 lines
- Richard's implementation had
__PIC__mean abicalls. Our patch changed__PIC__to mean pic2 abicalls only. I've included that in this patch. My reasoning is that most non-pic non-abicalls code works properly even with pic0 abicalls; the only problem is indirect calls through a register other than $25. This lets glibc automatically use some more efficient sequences in static applications.
Hmm, OK. It's the less conservative choice, but I agree it's also the best performance-wise.
Quoted 8 lines
- I added
pointer_equality_neededsupport to binutils to suppress settingst_valueto the PLT entry in most cases.- The GCC new-static-chain.patch causes nested-func-4.exe to fail.
_mcountis called through a PLT entry, which clobbers $15. I believe we need to add this toMIPS_SAVE_REG_FOR_PROFILING_P. I didn't fix this yet.
Quoted 6 lines
- no-fn-name-already-declared.patch removed the call to
ASM_OUTPUT_TYPE_DIRECTIVEfor Linux. .ent has similar effect, but is suppressed byflag_inhibit_size_directive. This caused glibc's_initto beSTT_OBJECT, and not get a PIC call stub. I've changed GCC to emit .type for all platforms; Richard, if this should be restricted to the status quo (i.e. Linux) let me know.
No, that sounds right to me FWIW.
Quoted 2 lines
Also the
STT_FUNCcheck in the linker was unnecessary now that we only use la25 stubs for jump relocations.
Agreed.
Sorry for the bugs, and thanks for fixing them. I'll try to have a look at the patches over the weekend.
Richard
Quoted 8 lines · Richard Sandiford
Quoted 4 lines
- I've dropped support for a non-fixed $gp. This is a handy optimization, but it was getting in the way and it was the part of the GCC patch Richard had the most comments on. I can resubmit it after everything else is merged.
That's a shame. It was also the bit I liked best ;) What went wrong?
(My comments were only minor.)
Nothing big: but it made up the bulk of our GCC patch, and I was rebasing on top of yours. We had a lot of trouble getting that bit to work, so I took the conservative path and dropped it. Don't worry - I definitely will return to this as soon as the remaining patches are merged; I liked it too.
Originally, we were also going to make small data work with non-PIC abicalls. I'd like to discuss that with you at some later date too. We ran into a lot of trouble combining small data with a non-fixed $gp; I believe it was because reload may introduce small data loads very late. I'd have to try it again before I had anything more sensible to say, though.
Quoted 2 lines
Sorry for the bugs, and thanks for fixing them. I'll try to have a look at the patches over the weekend.
No problem, and thank you for looking at them - and for your patches; I'm really pretty happy with the combined work.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery
Quoted 5 lines · Daniel Jacobowitz
All comments welcome - Richard, especially from you. How would you like to proceed? I think the first step should be to get your other binutils/gcc patches merged, including MIPS16 PIC; I used those as a base. But see a few of the notes for potential problems with those patches.
Yeah, Nick's approved most of the remaining binutils changes (thanks). I haven't applied them yet because of the doubt over whether st_size should be even or odd for ISA-encoded MIPS16 symbols. I don't really have an opinion, so I'll accept a maintainerly decision...
Anyway, the gcc patch looks good to me, thanks. The only niggle I could see was that you didn't update the comment for:
+/* True if the output file is marked as ".abicalls; .option pic0"
+ (-call_mixed). This is a GNU extension. */
+#define TARGET_ABICALLS_PIC0 \
+ (TARGET_ABSOLUTE_ABICALLS && TARGET_PLT)
(That kind of thing was inevitable given the amount of code you had to wade through. I'm impressed if there's really only one instance!) I think the gcc side is good to go, modulo the _mcount thing.
As far as binutils goes, I saw a couple of potential problems:
(1) The patch adds the following code to
_bfd_mips_elf_create_dynamic_sections:
+ if (htab->use_plts_and_copy_relocs && htab->root.hplt == NULL)
+ {
+ h = _bfd_elf_define_linkage_sym (abfd, info, s,
+ "_PROCEDURE_LINKAGE_TABLE_");
+ htab->root.hplt = h;
+ if (h == NULL)
+ return FALSE;
+ h->type = STT_FUNC;
+ }
But use_plts_and_copy_relocs is only set after all input bfds have been read in.
(2) The patch sets pointer_equality_needed as follows:
@@ -7432,9 +7484,18 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
elf_hash_table (info)->dynobj = dynobj = abfd;
break;
}
- /* Fall through */
+ /* Fall through. */
default:
+ /* Most static relocations require pointer equality, except
+ for branches. */
+ if (h)
+ h->pointer_equality_needed = TRUE;
+ /* Fall through. */
+
+ case R_MIPS_26:
+ case R_MIPS_PC16:
+ case R_MIPS16_26:
if (h)
((struct mips_elf_link_hash_entry *) h)->has_static_relocs = TRUE;
break;
But pointer equality is needed for non-call GOT relocations too. I couldn't see anything that explicitly handled that case.
I think it would be more robust to set pointer_equality_needed in a separate block, rather than combining it with the existing switch statements. It might then be clearer to set has_nonpic_branches in the new block too, so that you don't need two copies of:
if (h && !PIC_OBJECT_P (abfd))
((struct mips_elf_link_hash_entry *) h)->has_nonpic_branches = TRUE;
Some minor nits too:
+ 0x03990000, /* l[wd] $25, %lo(&GOTPLT[0])($28) */ + 0x01d90000, /* l[wd] $25, %lo(&GOTPLT[0])($14) */ + 0x01d90000, /* l[wd] $25, %lo(&GOTPLT[0])($14) */
These are all fixed as either lw or ld.
@@ -1649,13 +1695,16 @@ mips_elf_check_symbols (struct mips_elf_
/* H is a function that might need $25 to be valid on entry.
If we're creating a non-PIC relocatable object, mark H as being PIC. If we're creating a non-relocatable object with
- non-PIC references to H, make sure that H has an la25 stub. */
+ branches to H, make sure that H has an la25 stub. Only
+ use the stub for branches from non-PIC objects; GCC's
+ -mno-shared uses branches from PIC objects to functions
+ which do not require $25. */
if (hti->info->relocatable)
{
if (!PIC_OBJECT_P (hti->output_bfd))
h->root.other = ELF_ST_SET_MIPS_PIC (h->root.other);
}
- else if (h->non_pic_ref && !mips_elf_add_la25_stub (hti->info, h))
+ else if (h->has_nonpic_branches && !mips_elf_add_la25_stub (hti->info, h))
{
hti->error = TRUE;
return FALSE;
How about something like the following:
- non-PIC references to H, make sure that H has an la25 stub. */
+ non-PIC branches and jumps to H, make sure that H has an la25 stub.
+ We specifically ignore branches and jumps from EF_PIC objects,
+ where the onus is on the compiler or programmer to perform any
+ necessary initialization of $25. Sometimes such initialization
+ is unnecessary; for example, -mno-shared functions do not use
+ the incoming value of $25, and may therefore be called directly. */
(Wordsmith as necessary.) The original wording made it sound like we'd created a stub if there were any branches at all, but that the stub would only be used for branches from non-PIC objects.
@@ -2928,6 +2977,7 @@ mips_elf_gotplt_index (struct bfd_link_i
struct mips_elf_link_hash_table *htab;
htab = mips_elf_hash_table (info);
+ BFD_ASSERT (htab->is_vxworks);
BFD_ASSERT (h->plt.offset != (bfd_vma) -1);
/* Calculate the index of the symbol's PLT entry. */
I think this deserves a comment. (It's because the .got.plt address calculation is no longer accurate after the addition of the reserved entries, right?) I realise this function isn't used for non-VxWorks before the patch, but it's a generic concept even so...
@@ -4969,6 +5009,14 @@ mips_elf_calculate_relocation (bfd *abfd
BFD_ASSERT (sec->size > 0);
symbol = sec->output_section->vma + sec->output_offset;
}+ /* If this is a direct call to a PIC function, redirect to the
+ non-PIC stub. */
+ else if (h != NULL && h->la25_stub && !PIC_OBJECT_P (input_bfd)
+ && (r_type == R_MIPS_26 || r_type == R_MIPS_PC16
+ || r_type == R_MIPS16_26))
+ symbol = (h->la25_stub->stub_section->output_section->vma
+ + h->la25_stub->stub_section->output_offset
+ + h->la25_stub->offset);
/* Calls from 16-bit code to 32-bit code and vice versa require the
special jalx instruction. */
I'd prefer to see some part of:
(h != NULL
&& !PIC_OBJECT_P (input_bfd)
&& (r_type == R_MIPS_26 || r_type == R_MIPS_PC16
|| r_type == R_MIPS16_26))be a separate function that is used both here and in _bfd_mips_elf_check_relocs. At least the r_type check; I don't mind how much else. I just think the reloc code generally is tricky enough that even small decisions like this are worth abstracting out.
- htab->plt_header_size = 4 * ARRAY_SIZE (mips_exec_plt0_entry);
+ htab->plt_header_size = 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry);
Probably worth a comment saying that all the plt headers are the same size. It looked a bit odd using something with "o32" in it for n32 and n64.
if (h && !PIC_OBJECT_P (abfd)) ((struct mips_elf_link_hash_entry *) h)->has_nonpic_branches = TRUE;
+ /* Refuse some position-dependent relocations when creating a
+ shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
+ not PIC, but we can create dynamic relocations and the result
+ will be fine. Also do not refuse R_MIPS_LO16, which can be
+ combined with R_MIPS_GOT16. */
+ if (info->shared)
+ {
+ switch (r_type)
+ {
+ case R_MIPS16_HI16:
+ case R_MIPS_HI16:
+ case R_MIPS_HIGHER:
+ case R_MIPS_HIGHEST:+ /* Don't refuse a high part relocation if it's against
+ no symbol (e.g. part of a compound relocation). */
+ if (r_symndx == 0)
+ break;
+
+ /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
+ and has a special meaning. */
+ if (!NEWABI_P (abfd) && h != NULL
+ && strcmp (h->root.root.string, "_gp_disp") == 0)
+ break;
+
+ /* FALLTHROUGH */
+
+ case R_MIPS16_26:
+ case R_MIPS_26:
+ howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, FALSE);
+ (*_bfd_error_handler)
+ (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
+ abfd, howto->name,
+ (h) ? h->root.root.string : "a local symbol");
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ default:
+ break;
+ }
+ }
FWIW, I thought about adding this too, but rejected it because I was afraid of trapping valid uses. E.g. it makes it impossible to use relocations against SHN_ABS symbols, even though such symbols aren't (generally) subject to runtime relocation. I realise you copied this from other ports though.
@@ -8430,10 +8540,16 @@ _bfd_mips_elf_size_dynamic_sections (bfd
else if (SGI_COMPAT (output_bfd)
&& CONST_STRNEQ (name, ".compact_rel"))
s->size += mips_elf_hash_table (info)->compact_rel_size;
+ else if (s == htab->splt)
+ {
+ /* If the last PLT entry has a branch delay slot, allocate
+ room for an extra nop to fill the delay slot. */
+ if (!htab->is_vxworks && !info->shared && s->size > 0)
+ s->size += 4;
+ }
else if (! CONST_STRNEQ (name, ".init")
&& s != htab->sgot
&& s != htab->sgotplt
- && s != htab->splt
&& s != htab->sstubs
&& s != htab->sdynbss)
{
Why !info->shared?
@@ -9604,17 +9727,21 @@ mips_finish_exec_plt (bfd *output_bfd, s
gotplt_value_high = ((gotplt_value + 0x8000) >> 16) & 0xffff; gotplt_value_low = gotplt_value & 0xffff;
+ /* The PLT sequence is not safe for N64 if .got.plt is above the 2GB
+ mark. */
+ BFD_ASSERT ((gotplt_value >> 31) == 0);
+
/* Pick the load opcode. */
load = MIPS_ELF_LOAD_WORD (output_bfd);
/* Install the PLT header. */
loc = htab->splt->contents;
- bfd_put_32 (output_bfd, plt_entry[0] | got_value_high, loc); - bfd_put_32 (output_bfd, plt_entry[1] | got_value_low | load, loc + 4); - bfd_put_32 (output_bfd, plt_entry[2] | got_value_low, loc + 8); - bfd_put_32 (output_bfd, plt_entry[3] | gotplt_value_high, loc + 12); + bfd_put_32 (output_bfd, plt_entry[0] | gotplt_value_high, loc); + bfd_put_32 (output_bfd, plt_entry[1] | gotplt_value_low | load, loc + 4); + bfd_put_32 (output_bfd, plt_entry[2] | gotplt_value_low, loc + 8); + bfd_put_32 (output_bfd, plt_entry[3], loc + 12);
bfd_put_32 (output_bfd, plt_entry[4], loc + 16);
- bfd_put_32 (output_bfd, plt_entry[5] | gotplt_value_low, loc + 20);
+ bfd_put_32 (output_bfd, plt_entry[5], loc + 20); bfd_put_32 (output_bfd, plt_entry[6], loc + 24); bfd_put_32 (output_bfd, plt_entry[7], loc + 28);
}
I think it'd be good to tighten the assert, as it would currently trigger for valid X >= -0x80000000 addresses (both in 32-bit and 64-bit code). I don't know of any system out there that allows dynamic executables in kernel space, but I've ceased to be surprised by such things ;)
+/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ +
+bfd_boolean
+_bfd_mips_elf_hash_symbol (struct elf_link_hash_entry *h)
+{
+ struct mips_elf_link_hash_entry *hmips;
+
+ hmips = (struct mips_elf_link_hash_entry *) h;
+ if (h->plt.offset != MINUS_ONE
+ && hmips->no_fn_stub + && !h->def_regular + && !h->pointer_equality_needed)
+ return FALSE;
+
+ return _bfd_elf_hash_symbol (h);
+}
Were you able to test this, given:
static voidmips_after_parse (void)
{
/* .gnu.hash and the MIPS ABI require .dynsym to be sorted in different
ways. .gnu.hash needs symbols to be grouped by hash code whereas the MIPS ABI requires a mapping between the GOT and the symbol table. */
if (link_info.emit_gnu_hash)
{
einfo ("%X%P: .gnu.hash is incompatible with the MIPS ABI\n");
link_info.emit_hash = TRUE;
link_info.emit_gnu_hash = FALSE;
} after_parse_default ();
}
? FWIW, if it's dead code, I'd prefer to leave it out.
+ printf (_(" Entries:\n"));
+ printf (_(" %*s %*s %*s %-7s %3s %s\n"),
+ addr_size * 2, "Address", + addr_size * 2, "Initial", + addr_size * 2, "Sym.Val.", "Type", "Ndx", "Name");
+ sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
"- 17" rather than "- 28"? In the global GOT code, "28 - addr_size * 6" is the width of the format before the final "%s". However, the global GOT entries have an additional 10-char field and space separator, so the width there is 11 greater than here.
ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.dd +38 -36
@@ -2,50 +2,52 @@ # # -32752: lazy resolution function # -32748: reserved for module pointer -# -32744: PLT resolution function -# -32740: GOT page entry. -# -32736: bar's GOT entry +# -32744: GOT page entry. +# -32740: bar's GOT entry .* Disassembly of section \.plt: -00043010 <.*>: - 43010: 3c0f000a lui t7,0xa - 43014: 8df90008 lw t9,8\(t7\) - 43018: 25ef0008 addiu t7,t7,8 - 4301c: 3c0e0008 lui t6,0x8 - 43020: 03200008 jr t9 - 43024: 25ce1000 addiu t6,t6,4096 - \.\.\. +.* <.*>: +.*: 3c1c0008 lui gp,0x8 +.*: 8f991000 lw t9,4096\(gp\) +.*: 279c1000 addiu gp,gp,4096 +.*: 031cc023 subu t8,t8,gp +.*: 03e07821 move t7,ra +.*: 0018c082 srl t8,t8,0x2 +.*: 0320f809 jalr t9 +.*: 2718fffe addiu t8,t8,-2 + +.* <foo@plt>: +.*: 3c0f0008 lui t7,0x8 +.*: 8df91008 lw t9,4104\(t7\) +.*: 25f81008 addiu t8,t7,4104 +.*: 03200008 jr t9 +.*: 00000000 nop -00043030 <foo@plt>: - 43030: 3c180008 lui t8,0x8 - 43034: 8f191000 lw t9,4096\(t8\) - 43038: 03200008 jr t9 - 4303c: 27181000 addiu t8,t8,4096 Disassembly of section \.text: -00044000 <__start>: - 44000: 0c010c0c jal 43030 <foo@plt> - 44004: 00000000 nop - 44008: 08011004 j 44010 <ext> - 4400c: 00000000 nop - -00044010 <ext>: - 44010: 3c1c000a lui gp,0xa - 44014: 279c7ff0 addiu gp,gp,32752 - 44018: 8f82801c lw v0,-32740\(gp\) - 4401c: 24421000 addiu v0,v0,4096 - 44020: 8f998020 lw t9,-32736\(gp\) - 44024: 03200008 jr t9 - 44028: 00000000 nop - 4402c: 00000000 nop +.* <__start>: +.*: 0c010c10 jal 43040 <foo@plt> +.*: 00000000 nop +.*: 08011004 j 44010 <ext> +.*: 00000000 nop + +.* <ext>: +.*: 3c1c000a lui gp,0xa +.*: 279c7ff0 addiu gp,gp,32752 +.*: 8f828018 lw v0,-32744\(gp\) +.*: 24421000 addiu v0,v0,4096 +.*: 8f99801c lw t9,-32740\(gp\) +.*: 03200008 jr t9 +.*: 00000000 nop +.*: 00000000 nop Disassembly of section .MIPS.stubs: -00044030 <\.MIPS\.stubs>: - 44030: 8f998010 lw t9,-32752\(gp\) - 44034: 03e07821 move t7,ra - 44038: 0320f809 jalr t9 - 4403c: 24180007 li t8,7 +.* <\.MIPS\.stubs>: +.*: 8f998010 lw t9,-32752\(gp\) +.*: 03e07821 move t7,ra +.*: 0320f809 jalr t9 +.*: 24180007 li t8,7 \.\.\.
Please keep the "... <...>:" addresses at least. (You did this in some of the other tests, thanks.) The non-disassembly dumps rely on functions being at certain addresses, and I think it's easier to follow the test if those addresses are explicit in the disassembly.
(I've used custom scripts for this sort of test to try to protect them from fluctuations in the size of the dynamic info. The addresses should be pretty stable.)
Richard
Quoted 11 lines · Richard Sandiford
Quoted 5 lines · Daniel Jacobowitz
All comments welcome - Richard, especially from you. How would you like to proceed? I think the first step should be to get your other binutils/gcc patches merged, including MIPS16 PIC; I used those as a base. But see a few of the notes for potential problems with those patches.
Yeah, Nick's approved most of the remaining binutils changes (thanks). I haven't applied them yet because of the doubt over whether
st_sizeshould be even or odd for ISA-encoded MIPS16 symbols. I don't really have an opinion, so I'll accept a maintainerly decision...
[I'm not sure if this is a helpful suggestion or not, so feel free to ignore it if it's not.]
I would suggest that st_size be the actual size of the function, as it lives in memory. A test of it's start/end location is "could I stick a random data byte there and have it affect the function". For example, for a Thumb function whose ISA address is "0x00000001", I would consider for size purposes that it starts at "0x00000000", since altering that byte at run-time would change the meaning of the function.
Signature · 4 lines
Mark Mitchell CodeSourcery [email protected] (650) 331-3385 x713
Quoted 16 lines · Mark Mitchell
Quoted 11 lines · Richard Sandiford
Quoted 5 lines · Daniel Jacobowitz
All comments welcome - Richard, especially from you. How would you like to proceed? I think the first step should be to get your other binutils/gcc patches merged, including MIPS16 PIC; I used those as a base. But see a few of the notes for potential problems with those patches.
Yeah, Nick's approved most of the remaining binutils changes (thanks). I haven't applied them yet because of the doubt over whether
st_sizeshould be even or odd for ISA-encoded MIPS16 symbols. I don't really have an opinion, so I'll accept a maintainerly decision...[I'm not sure if this is a helpful suggestion or not, so feel free to ignore it if it's not.]
Quoted 6 lines
I would suggest that
st_sizebe the actual size of the function, as it lives in memory. A test of it's start/end location is "could I stick a random data byte there and have it affect the function". For example, for a Thumb function whose ISA address is "0x00000001", I would consider for size purposes that it starts at "0x00000000", since altering that byte at run-time would change the meaning of the function.
For the record, my reasoning when picking the odd st_size was similar, but with the opposite outcome. The point of using an ISA-encoded st_value is that that's what most users want. Most of them won't even have code to say "is this a MIPS16 symbol?".
So if users are going to get into the habit of using MIPS st_values without checking the "ISA bit", I thought it was more conservative to base the end address on the unmodified st_value rather than the modified one. In other words, I thought it was more conservative to have "st_value + st_size" be the end point of the function, rather than "(st_value & ~1) + st_size". This ensures that "st_value" and "st_value + st_size - 1" are bytes in the function, rather than making "st_value + st_size" be two bytes past the end of the function (and thus making "st_value + st_size - 1" refer to something outside the function).
But like I say, I can see there are pros and cons both ways, so I don't really have an opinion. I'm happy to (and do) accpet Dan's decision. And I guess the ARM experience shows that my concern isn't really an issue in practice anyway.
Richard