good code: .intel_syntax .globl main main: jmp DWORD PTR[ %edx + var_1 - 0x1000 ] var_1: .byte 0x11, 0x22, 0x33, 0x44 code generated: (objdump rip) 08048394 <main>: 8048394: ff a2 9a 73 04 08 jmp *0x804739a(%edx) 0804839a <var_1>: ... the jmp correctly references var_1 - 0x1000 (0804839a -0x1000 = 0x804739a) but modified code: .intel_syntax .globl main var_1: .byte 0x11, 0x22, 0x33, 0x44 main: jmp DWORD PTR[ %edx + var_1 - 0x1000 ] code generated: (objdump rip) 08048394 <var_1>: 8048394: 11 22 8048396: 33 44 08048398 <main>: 8048398: ff a2 94 83 04 08 jmp *0x8048394(%edx) the jmp directly accesses var_1 it seems to forget to add -0x1000 to memory deref $ as --version GNU assembler (GNU Binutils for Debian) 2.20
It is a regression. Binutils 2.19 works correctly.
It is an assembler bug.
It is caused by: http://sourceware.org/ml/binutils-cvs/2009-10/msg00245.html
Created attachment 4449 [details] A patch The problem is in else if (seg_left == undefined_section && add_symbol != orig_add_symbol) seg_left == undefined_section is wrong. However, add_symbol != orig_add_symbol isn't reliable since local symbol may be converted. This patch works for the testcase. If it is OK, I will submit a complete patch with some testcases.
Ah ha! I wanted to get rid of seg_left == undefined_section too, but hadn't spotted the problem with local symbols. Your patch looks good except for the calls to local_symbol_convert, which are unnecessary work and memory usage.
A patch is posted at http://sourceware.org/ml/binutils/2009-12/msg00095.html
Subject: Bug 11037 CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2009-12-08 03:14:29 Modified files: gas : ChangeLog expr.c symbols.c symbols.h gas/testsuite : ChangeLog gas/testsuite/gas/i386: intelpic.d intelpic.s Log message: Call symbol_same_p to check to if 2 symbols are the same. gas/ 2009-12-07 H.J. Lu <hongjiu.lu@intel.com> PR gas/11037 * expr.c (resolve_expression): Call symbol_same_p to check if 2 symbols are the same. * symbols.c (symbol_same_p): New. * symbols.h (symbol_same_p): Likewise. gas/testsuite/ 2009-12-07 H.J. Lu <hongjiu.lu@intel.com> PR gas/11037 * gas/i386/intelpic.s: Add testcases. * gas/i386/intelpic.d: Updated. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4034&r2=1.4035 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/expr.c.diff?cvsroot=src&r1=1.79&r2=1.80 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/symbols.c.diff?cvsroot=src&r1=1.100&r2=1.101 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/symbols.h.diff?cvsroot=src&r1=1.31&r2=1.32 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1601&r2=1.1602 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/intelpic.d.diff?cvsroot=src&r1=1.4&r2=1.5 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/intelpic.s.diff?cvsroot=src&r1=1.2&r2=1.3
HJ, please apply your patch to the 2.20 branch so the bug can be closed.
Subject: Bug 11037 CVSROOT: /cvs/src Module name: src Branch: binutils-2_20-branch Changes by: hjl@sourceware.org 2009-12-16 01:52:14 Modified files: gas : ChangeLog expr.c symbols.c symbols.h gas/testsuite : ChangeLog gas/testsuite/gas/i386: intelpic.d intelpic.s Log message: Fix PR gas/11037. gas/ 2009-12-15 H.J. Lu <hongjiu.lu@intel.com> Backport from trunk: 2009-12-07 H.J. Lu <hongjiu.lu@intel.com> PR gas/11037 * expr.c (resolve_expression): Call symbol_same_p to check if 2 symbols are the same. * symbols.c (symbol_same_p): New. * symbols.h (symbol_same_p): Likewise. gas/testsuite/ 2009-12-15 H.J. Lu <hongjiu.lu@intel.com> Backport from trunk: 2009-12-07 H.J. Lu <hongjiu.lu@intel.com> PR gas/11037 * gas/i386/intelpic.s: Add testcases. * gas/i386/intelpic.d: Updated. 2009-10-28 Alan Modra <amodra@bigpond.net.au> * gas/i386/intelpic.d: Correct. 2009-10-08 H.J. Lu <hongjiu.lu@intel.com> PR gas/10704 * gas/i386/intelpic.s: Add 2 new tests. * gas/i386/intelpic.d: Updated. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.3938.2.29&r2=1.3938.2.30 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/expr.c.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.77.2.2&r2=1.77.2.3 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/symbols.c.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.96.2.4&r2=1.96.2.5 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/symbols.h.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.31&r2=1.31.2.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.1537.2.14&r2=1.1537.2.15 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/intelpic.d.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.2&r2=1.2.4.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/intelpic.s.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.1&r2=1.1.34.1
Fixed.