Created attachment 6582 [details] Assembly source file As seen at the following assembly listing: GNU assembler version 2.22.0 (pdp11-aout) using BFD version (GNU Binutils) 2.22.0.20120725 GAS LISTING dic.s page 1 1 0000 C0151000 start: mov $ind,r0 2 0004 C809 jsr pc,@(r0) 3 0006 F8090000 jsr pc,@0(r0) 4 000a F8090200 jsr pc,@2(r0) 5 000e 0000 halt 6 7 8 0010 1400 ind: .WORD dest 9 0012 1600 .WORD dest2 10 11 0014 8700 dest: rts pc 12 13 0016 8700 dest2: rts pc 14 15 .END The instructions in lines 2 and 3 should both assemble to F8090000, but line 2 assembles like it was JSR PC,(R0).
See the NOTE at the bottom of page 5-5 in Section 5.8, INDEX DEFERRED MODE, in the PDP-11 MACRO-11 Language Reference Manual on the BitSavers web site (http://www.bitsavers.org/pdf/dec/pdp11/rsx11/RSX11M_V4.1_Apr83/4_ProgramDevelopment/AA-V027A-TC_macro11_Mar83.pdf): The expression @(ER) may be used, but it will be assembled as if it were written @0(ER), and a word will be used to store the 0.
Additional information: the gcc compiler generates a JSR PC,@(Rx) to implement an indirect call thru a function pointer table, so this bug causes gcc generating invalid code.
Created attachment 11146 [details] Modified Assembly Program illustrating the problem Added a line to show that the current behavior does produce output matching something it shouldn't match.
Created attachment 11147 [details] Patch which solves this specific problem
Confirming that this bug still exists in as 2.31.51.20180719. Attached is a slightly modified version of Jordi's dic.s called dic-mod.s. The output of pdp11-aout-as -a dic-mod.s is: GAS LISTING /home/cptnapalm/Downloads/dic-mod.s page 1 1 0000 C0151200 start:mov$ind,r0 2 0004 C809 jsr pc,(r0) 3 0006 C809 jsr pc,@(r0) 4 0008 F8090000 jsr pc,@0(r0) 5 000c F8090200 jsr pc,@2(r0) 6 0010 0000 halt 7 8 9 0012 1600 ind:.WORDdest 10 0014 1800 .WORDdest2 11 12 0016 8700 dest:rtspc 13 14 0018 8700 dest2:rtspc 15 16 .END GAS LISTING /home/cptnapalm/Downloads/dic-mod.s page 2 DEFINED SYMBOLS /home/cptnapalm/Downloads/dic-mod.s:1 .text:0000000000000000 start /home/cptnapalm/Downloads/dic-mod.s:9 .text:0000000000000012 ind /home/cptnapalm/Downloads/dic-mod.s:12 .text:0000000000000016 dest /home/cptnapalm/Downloads/dic-mod.s:14 .text:0000000000000018 dest2 NO UNDEFINED SYMBOLS As can be seen, jsr pc,@(r0) assembles the same as jsr pc,(r0), which it shouldn't do. I created a patch, which is attached, that solves this problem. As adding a '0' would create a new string and since it already knows that it's deferred, I just replace the '@' with a '0' before sending it along. The new output: GAS LISTING /home/cptnapalm/Downloads/dic-mod.s page 1 1 0000 C0151400 start: mov $ind,r0 2 0004 C809 jsr pc,(r0) 3 0006 F8090000 jsr pc,@(r0) 4 000a F8090000 jsr pc,@0(r0) 5 000e F8090200 jsr pc,@2(r0) 6 0012 0000 halt 7 8 9 0014 1800 ind: .WORD dest 10 0016 1A00 .WORD dest2 11 12 0018 8700 dest: rts pc 13 14 001a 8700 dest2: rts pc 15 16 .END GAS LISTING /home/cptnapalm/Downloads/dic-mod.s page 2 DEFINED SYMBOLS /home/cptnapalm/Downloads/dic-mod.s:1 .text:0000000000000000 start /home/cptnapalm/Downloads/dic-mod.s:9 .text:0000000000000014 ind /home/cptnapalm/Downloads/dic-mod.s:12 .text:0000000000000018 dest /home/cptnapalm/Downloads/dic-mod.s:14 .text:000000000000001a dest2 NO UNDEFINED SYMBOLS It now does the right thing in this case.
Hold off on the 2018-07-19 patch. There are some additional fixes necessary.
Created attachment 11156 [details] Fixes implicit index deferred @(Rn) now changes to @0(Rn) as it should. @(Rn)+ is explicitly tested for and remains unchanged.
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3cf2b6691cef024f7cdb48aaec5fab5189e1cffa commit 3cf2b6691cef024f7cdb48aaec5fab5189e1cffa Author: James Patrick Conlon <cptjustice@gmail.com> Date: Wed Aug 1 15:14:46 2018 +0100 Fix bug in PDP11 assembler when handling a JSr instruction with deferred auto increment. PR 14480 * config/tc-pdp11.c (parse_op_noreg): Check for and handle auto increment deferred. * testsuite/gas/pdp11/pr14480.d: New test driver file. * testsuite/gas/pdp11/pr14480.s: New test source file file. * testsuite/gas/pdp11/pdp11.exp: Run the new test.
Hi James, Thanks for the patch. I have applied it, along with an addition to the PDP11 assembler testsuite, to the mainline sources. I did make one addition to the patch. Just a small paranoia check to make sure that the bytes between str[1] and str[5] are not NUL. Cheers Nick