diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2012-11-06 00:47:20 +0400 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2012-11-06 00:47:20 +0400 |
commit | 7ce86b500c792b782b7b076f50b220fc62234954 (patch) | |
tree | 3253796ab97cd3d19c33a8be183a6903d4e93767 /output | |
parent | f1fe4fdeabeaf2e5e4d02ef43beeb09a6fbfed1b (diff) | |
download | nasm-7ce86b500c792b782b7b076f50b220fc62234954.tar.gz nasm-7ce86b500c792b782b7b076f50b220fc62234954.tar.bz2 nasm-7ce86b500c792b782b7b076f50b220fc62234954.zip |
BR3392231: Fix get_closest_section_symbol_by_offset
This patch changes get_closest_section_symbol_by_offset
logic to lookup only the closest symbols which are at
or before the supplied offset.
Signed-off-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'output')
-rw-r--r-- | output/outmac64.c | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/output/outmac64.c b/output/outmac64.c index 6dc0c44..b26ff24 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -299,37 +299,20 @@ 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 *nearest = NULL; - int64_t sval, nval, sdiff, ndiff; - - 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; - } + struct symbol *sym; - /* Symbols should be in order, so this optimization should be OK */ - if((int64_t)nearest->value >= offset){ - break; - } - } + for (sym = syms; sym; sym = sym->next) { + if ((sym->sect != NO_SECT) && (sym->sect == fileindex)) { + if ((int64_t)sym->value > offset) + break; + nearest = sym; } } return nearest; } - /* * Special section numbers which are used to define Mach-O special * symbols, which can be used with WRT to provide PIC relocation |