NASM compiling x86_64 ASM label addresses off by 256 bytes in Mach-O when using multiple db declarations?

后端 未结 2 400
时光取名叫无心
时光取名叫无心 2020-12-03 23:25

In short, when I have multiple db sections in my .data section, the compiled addresses/labels are off when compiled by NASM. In my testing they are

相关标签:
2条回答
  • 2020-12-03 23:35

    Yes, it's a bug in Nasm-2.11.08. Nasm-2.11.06 should work. Nasm-2.11.09rc1 should work(?). Sorry 'bout that!

    0 讨论(0)
  • 2020-12-03 23:48

    The related issue can be found here:

    Bug 3392306 - Issue with relative addressing and data section

    The current version of 2.11.08 available by Homebrew patches this issue with the following diff file:

    https://raw.githubusercontent.com/Homebrew/patches/7a329c65e/nasm/nasm_outmac64.patch

    From 4920a0324348716d6ab5106e65508496241dc7a2 Mon Sep 17 00:00:00 2001
    From: Cyrill Gorcunov <gorcunov@gmail.com>
    Date: Sat, 9 May 2015 18:07:47 +0300
    Subject: [PATCH] output: outmac64 -- Fix the case when first hit matches the
     symbol
    
    In case if we're looking up for a symbol and it's first
    one in symbol table we might endup with error because of
    using GE here (78f477b35f) ending cycle with @nearest = NULL.
    
    http://bugzilla.nasm.us/show_bug.cgi?id=3392306
    
    Reprted-by: Benjamin Randazzo <benjamin@linuxcrashing.org>
    Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
    ---
     output/outmac64.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/output/outmac64.c b/output/outmac64.c
    index c07dcbc..1d30e64 100644
    --- a/output/outmac64.c
    +++ b/output/outmac64.c
    @@ -304,7 +304,7 @@ static struct symbol *get_closest_section_symbol_by_offset(uint8_t fileindex, in
    
         for (sym = syms; sym; sym = sym->next) {
             if ((sym->sect != NO_SECT) && (sym->sect == fileindex)) {
    -            if ((int64_t)sym->value >= offset)
    +            if ((int64_t)sym->value > offset)
                     break;
                 nearest = sym;
             }
    -- 
    2.4.10.GIT
    

    So if you are installing via Homebrew, this problem should now be resolved.

    0 讨论(0)
提交回复
热议问题