mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-30 16:41:05 +08:00
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:
parent
559d936ad7
commit
ca2a788edf
@ -1277,6 +1277,7 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r)
|
|||||||
{
|
{
|
||||||
struct SAA *s;
|
struct SAA *s;
|
||||||
uint8_t *p, entry[8];
|
uint8_t *p, entry[8];
|
||||||
|
int32_t global_offset;
|
||||||
|
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1284,6 +1285,13 @@ static struct SAA *elf_build_reltab(int32_t *len, struct Reloc *r)
|
|||||||
s = saa_init(1L);
|
s = saa_init(1L);
|
||||||
*len = 0;
|
*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) {
|
while (r) {
|
||||||
int32_t sym = r->symbol;
|
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.
|
* entries, the null entry and the filename entry.
|
||||||
*/
|
*/
|
||||||
if (sym >= GLOBAL_TEMP_BASE)
|
if (sym >= GLOBAL_TEMP_BASE)
|
||||||
sym += -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
|
sym += global_offset;
|
||||||
|
|
||||||
p = entry;
|
p = entry;
|
||||||
WRITELONG(p, r->address);
|
WRITELONG(p, r->address);
|
||||||
|
@ -1363,6 +1363,7 @@ static struct SAA *elf_build_reltab(uint64_t *len, struct Reloc *r)
|
|||||||
{
|
{
|
||||||
struct SAA *s;
|
struct SAA *s;
|
||||||
uint8_t *p, entry[24];
|
uint8_t *p, entry[24];
|
||||||
|
int32_t global_offset;
|
||||||
|
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1370,15 +1371,18 @@ static struct SAA *elf_build_reltab(uint64_t *len, struct Reloc *r)
|
|||||||
s = saa_init(1L);
|
s = saa_init(1L);
|
||||||
*len = 0;
|
*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) {
|
while (r) {
|
||||||
int32_t sym = r->symbol;
|
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)
|
if (sym >= GLOBAL_TEMP_BASE)
|
||||||
sym += -GLOBAL_TEMP_BASE + nsects + nlocals + ndebugs + 2;
|
sym += global_offset;
|
||||||
|
|
||||||
p = entry;
|
p = entry;
|
||||||
WRITEDLONG(p, r->address);
|
WRITEDLONG(p, r->address);
|
||||||
|
Loading…
Reference in New Issue
Block a user