ELF: remove loop invariant calculation of global offset

The global symbol offset is a loop invariant; no need to compute it
over and over.  The compiler probably will not be able to do this for
us due to global variables and function calls.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2009-06-25 17:30:58 -07:00
parent 559d936ad7
commit ca2a788edf
2 changed files with 18 additions and 6 deletions

View File

@ -1277,6 +1277,7 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r)
{
struct SAA *s;
uint8_t *p, entry[8];
int32_t global_offset;
if (!r)
return NULL;
@ -1284,6 +1285,13 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r)
s = saa_init(1L);
*len = 0;
/*
* How to onvert from a global placeholder to a real symbol index;
* the +2 refers to the two special entries, the null entry and
* the filename entry.
*/
global_offset = -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
while (r) {
int32_t sym = r->symbol;
@ -1292,7 +1300,7 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r)
* entries, the null entry and the filename entry.
*/
if (sym >= GLOBAL_TEMP_BASE)
sym += -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
sym += global_offset;
p = entry;
WRITELONG(p, r->address);

View File

@ -1363,6 +1363,7 @@ static struct SAA *elf_build_reltab(uint64_t *len, struct Reloc *r)
{
struct SAA *s;
uint8_t *p, entry[24];
int32_t global_offset;
if (!r)
return NULL;
@ -1370,15 +1371,18 @@ static struct SAA *elf_build_reltab(uint64_t *len, struct Reloc *r)
s = saa_init(1L);
*len = 0;
/*
* How to onvert from a global placeholder to a real symbol index;
* the +2 refers to the two special entries, the null entry and
* the filename entry.
*/
global_offset = -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
while (r) {
int32_t sym = r->symbol;
/*
* Create a real symbol index; the +2 refers to the two special
* entries, the null entry and the filename entry.
*/
if (sym >= GLOBAL_TEMP_BASE)
sym += -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
sym += global_offset;
p = entry;
WRITEDLONG(p, r->address);