diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-06-25 17:30:58 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-06-25 17:30:58 -0700 |
commit | ca2a788edfa310f758a7706e284361fcba10ebea (patch) | |
tree | 2596176854c1a9d871cb1021b62a3572fec25247 /output | |
parent | 559d936ad7de8330965f9b7456fe3cb48d49a386 (diff) | |
download | nasm-ca2a788edfa310f758a7706e284361fcba10ebea.tar.gz nasm-ca2a788edfa310f758a7706e284361fcba10ebea.tar.bz2 nasm-ca2a788edfa310f758a7706e284361fcba10ebea.zip |
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>
Diffstat (limited to 'output')
-rw-r--r-- | output/outelf32.c | 10 | ||||
-rw-r--r-- | output/outelf64.c | 14 |
2 files changed, 18 insertions, 6 deletions
diff --git a/output/outelf32.c b/output/outelf32.c index 832a503..fb5d1b0 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -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); diff --git a/output/outelf64.c b/output/outelf64.c index 44ff8e0..05a5356 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -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); |