summaryrefslogtreecommitdiff
path: root/output
diff options
context:
space:
mode:
authorChuck Crayne <ccrayne@users.sourceforge.net>2007-04-29 20:57:53 +0000
committerChuck Crayne <ccrayne@users.sourceforge.net>2007-04-29 20:57:53 +0000
commit8ab0320f02e23e840cf5b2bcca5f3dc74607709f (patch)
tree2f5b0224ca6e283e95c8f2ca9a55118a6f64c88c /output
parent1c270b7fe2b22794c7109f52d815afe9fd33a5c6 (diff)
downloadnasm-8ab0320f02e23e840cf5b2bcca5f3dc74607709f.tar.gz
nasm-8ab0320f02e23e840cf5b2bcca5f3dc74607709f.tar.bz2
nasm-8ab0320f02e23e840cf5b2bcca5f3dc74607709f.zip
Clarify comments about relocation entries.
Diffstat (limited to 'output')
-rw-r--r--output/outelf32.c28
-rw-r--r--output/outelf64.c29
2 files changed, 25 insertions, 32 deletions
diff --git a/output/outelf32.c b/output/outelf32.c
index cc5bef8..739417d 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -541,21 +541,14 @@ static void elf_deflabel(char *name, int32_t segment, int32_t offset,
if (sym->type == SYM_GLOBAL) {
/*
- * There's a problem here that needs fixing.
* If sym->section == SHN_ABS, then the first line of the
- * else section causes a core dump, because its a reference
+ * else section would cause a core dump, because its a reference
* beyond the end of the section array.
* This behaviour is exhibited by this code:
* GLOBAL crash_nasm
* crash_nasm equ 0
- *
- * I'm not sure how to procede, because I haven't got the
- * first clue about how ELF works, so I don't know what to
- * do with it. Furthermore, I'm not sure what the rest of this
- * section of code does. Help?
- *
- * For now, I'll see if doing absolutely nothing with it will
- * work...
+ * To avoid such a crash, such requests are silently discarded.
+ * This may not be the best solution.
*/
if (sym->section == SHN_UNDEF || sym->section == SHN_COMMON) {
bsym = raa_write(bsym, segment, nglobs);
@@ -1477,8 +1470,12 @@ void stabs32_generate(void)
/* this is the stab for the main source file */
WRITE_STAB(sptr, fileidx[mainfileindex], N_SO, 0, 0, 0);
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
+
+ /* Since the above WRITE_STAB calls have already */
+ /* created two entries, the index in the info.section */
+ /* member must be adjusted by adding 3 */
+
WRITELONG(rptr, (sptr - sbuf) - 4);
WRITELONG(rptr, ((ptr->info.section + 3) << 8) | R_386_32);
@@ -1497,8 +1494,7 @@ void stabs32_generate(void)
ptr->info.offset);
numstabs++;
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
WRITELONG(rptr, (sptr - sbuf) - 4);
WRITELONG(rptr, ((ptr->info.section + 3) << 8) | R_386_32);
}
@@ -1506,8 +1502,8 @@ void stabs32_generate(void)
WRITE_STAB(sptr, 0, N_SLINE, 0, ptr->line, ptr->info.offset);
numstabs++;
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
+
WRITELONG(rptr, (sptr - sbuf) - 4);
WRITELONG(rptr, ((ptr->info.section + 3) << 8) | R_386_32);
diff --git a/output/outelf64.c b/output/outelf64.c
index 6a2843a..6f0ee57 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -553,21 +553,14 @@ static void elf_deflabel(char *name, int32_t segment, int32_t offset,
if (sym->type == SYM_GLOBAL) {
/*
- * There's a problem here that needs fixing.
* If sym->section == SHN_ABS, then the first line of the
- * else section causes a core dump, because its a reference
+ * else section would cause a core dump, because its a reference
* beyond the end of the section array.
* This behaviour is exhibited by this code:
* GLOBAL crash_nasm
* crash_nasm equ 0
- *
- * I'm not sure how to procede, because I haven't got the
- * first clue about how ELF works, so I don't know what to
- * do with it. Furthermore, I'm not sure what the rest of this
- * section of code does. Help?
- *
- * For now, I'll see if doing absolutely nothing with it will
- * work...
+ * To avoid such a crash, such requests are silently discarded.
+ * This may not be the best solution.
*/
if (sym->section == SHN_UNDEF || sym->section == SHN_COMMON) {
bsym = raa_write(bsym, segment, nglobs);
@@ -1478,8 +1471,12 @@ void stabs64_generate(void)
/* this is the stab for the main source file */
WRITE_STAB(sptr, fileidx[mainfileindex], N_SO, 0, 0, 0);
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
+
+ /* Since the above WRITE_STAB calls have already */
+ /* created two entries, the index in the info.section */
+ /* member must be adjusted by adding 3 */
+
WRITEDLONG(rptr, (int64_t)(sptr - sbuf) - 4);
WRITEDLONG(rptr, ((int64_t)(ptr->info.section + 3) << 32) | R_X86_64_32);
@@ -1498,8 +1495,8 @@ void stabs64_generate(void)
ptr->info.offset);
numstabs++;
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
+
WRITEDLONG(rptr, (int64_t)(sptr - sbuf) - 4);
WRITEDLONG(rptr, ((int64_t)(ptr->info.section + 3) << 32) | R_X86_64_32);
}
@@ -1507,8 +1504,8 @@ void stabs64_generate(void)
WRITE_STAB(sptr, 0, N_SLINE, 0, ptr->line, ptr->info.offset);
numstabs++;
- /* relocation stuff */
- /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
+ /* relocation table entry */
+
WRITEDLONG(rptr, (int64_t)(sptr - sbuf) - 4);
WRITEDLONG(rptr, ((int64_t)(ptr->info.section + 3) << 32) | R_X86_64_32);