diff options
author | Keith Kanios <keith@kanios.net> | 2011-04-11 21:38:50 -0500 |
---|---|---|
committer | Keith Kanios <keith@kanios.net> | 2011-04-11 21:38:50 -0500 |
commit | 805266443346f4dcbc387508679a445f47e5f662 (patch) | |
tree | 26515ba48bb904240f8c8866c0c1e67820d69d55 /output | |
parent | 918317c4ce857458b219b132094eacd8e9b96931 (diff) | |
download | nasm-805266443346f4dcbc387508679a445f47e5f662.tar.gz nasm-805266443346f4dcbc387508679a445f47e5f662.tar.bz2 nasm-805266443346f4dcbc387508679a445f47e5f662.zip |
BR3282788: Fix 64-bit Mach-O bug that crashes NASM due to NULL symbols
Diffstat (limited to 'output')
-rw-r--r-- | output/outmac64.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/output/outmac64.c b/output/outmac64.c index f633db0..6dc0c44 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -299,16 +299,34 @@ static uint8_t get_section_fileindex_by_index(const int32_t index) static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, int64_t offset) { - struct symbol *sym; + struct symbol *sym; + struct symbol *nearest = NULL; + int64_t sval, nval, sdiff, ndiff; - for (sym = syms; sym != NULL; sym = sym->next) { - if ((sym->sect != NO_SECT) && - (sym->sect == fileindex) && - ((int64_t)sym->value >= offset)) - return sym; - } + for (sym = syms; sym != NULL; sym = sym->next) { + if ((sym->sect != NO_SECT) && (sym->sect == fileindex)){ + if(nearest == NULL){ + nearest = sym; + }else{ + sval = (int64_t)sym->value; + nval = (int64_t)nearest->value; + + sdiff = ((sval >= offset) ? (sval - offset) : (offset - sval)); + ndiff = ((nval >= offset) ? (nval - offset) : (offset - nval)); + + if(sdiff <= ndiff){ + nearest = sym; + } + + /* Symbols should be in order, so this optimization should be OK */ + if((int64_t)nearest->value >= offset){ + break; + } + } + } + } - return NULL; + return nearest; } |