Bug 54282 - GCC generates incorrect code for the PDP-11 target when -Os or -O2 is specified
Summary: GCC generates incorrect code for the PDP-11 target when -Os or -O2 is specified
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.4
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-16 12:46 UTC by Jordi Guillaumes Pons
Modified: 2012-08-16 16:20 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Compiler generated file (536 bytes, application/octet-stream)
2012-08-16 12:46 UTC, Jordi Guillaumes Pons
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jordi Guillaumes Pons 2012-08-16 12:46:11 UTC
Created attachment 28029 [details]
Compiler generated file

When doing an indirect function call (using a function pointer table), GCC generates incorrectly the JSR instruction. Assuming than R0 contains the address of the pointer to the function to call, the correct instruction would be:

JSR PC,@(R0)

The compiler generates instead:

JSR PC,(R0)

That causes the machine to jump to the pointer address instead of jumping to the function address.

Oddly enough, the assembly (*.s) file generated it I specify the -S option is right:


        mov _trap_table.1213+02(r0), -(sp)
        add $_trap_table.1213, r0
        jsr pc, @(r0)

But the compiled code in the *.o file, shown using the objdump utility is wrong:


 66:   1066            mov     r1, -(sp)
  68:   1c26 0082       mov     202(r0), -(sp)
  6c:   65c0 0080       add     $200, r0
  70:   09c8            jsr     pc, (r0)

Compiler output:

Usant especificacions internes.
COLLECT_GCC=pdp11-aout-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/pdp11-aout/4.6.4/lto-wrapper
Target: pdp11-aout
Configurat amb: ../gcc/configure --enable-languages=c --target=pdp11-aout --with-newlib
Model de fils: single
gcc version 4.6.4 20120725 (prerelease) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra'
 /usr/local/libexec/gcc/pdp11-aout/4.6.4/cc1 -E -quiet -v indirect_call_table.c -Wall -Wextra -Os -fpch-preprocess -o indirect_call_table.i
ignorant el directori inexistent "/usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/sys-include"
la recerca de #include  "..." s'inicia aquí:
la recerca de #include <...> s'inicia aquí:
 /usr/local/lib/gcc/pdp11-aout/4.6.4/include
 /usr/local/lib/gcc/pdp11-aout/4.6.4/include-fixed
 /usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/include
Fi de la llista de recerca.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra'
 /usr/local/libexec/gcc/pdp11-aout/4.6.4/cc1 -fpreprocessed indirect_call_table.i -quiet -dumpbase indirect_call_table.c -auxbase indirect_call_table -Os -Wall -Wextra -version -o indirect_call_table.s
GNU C (GCC) version 4.6.4 20120725 (prerelease) (pdp11-aout)
	compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.6.4 20120725 (prerelease) (pdp11-aout)
	compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4e94c29ebf077b5bb93c64c5b111b8f7
indirect_call_table.c: In function ‘muxx_systrap_handler’:
indirect_call_table.c:30:7: avís: variable ‘rc’ set but not used [-Wunused-but-set-variable]
indirect_call_table.c: In function ‘muxx_svc_conputc’:
indirect_call_table.c:48:1: avís: no hi ha una declaració de retorn en una funció que retorna "non-void" [-Wreturn-type]
indirect_call_table.c:44:33: avís: unused parameter ‘np’ [-Wunused-parameter]
indirect_call_table.c: In function ‘muxx_svc_muxxhlt’:
indirect_call_table.c:52:1: avís: no hi ha una declaració de retorn en una funció que retorna "non-void" [-Wreturn-type]
indirect_call_table.c:50:33: avís: unused parameter ‘np’ [-Wunused-parameter]
indirect_call_table.c:50:45: avís: unused parameter ‘args’ [-Wunused-parameter]
indirect_call_table.c: In function ‘muxx_unimpl’:
indirect_call_table.c:55:28: avís: unused parameter ‘np’ [-Wunused-parameter]
indirect_call_table.c:55:40: avís: unused parameter ‘args’ [-Wunused-parameter]
indirect_call_table.c: In function ‘muxx_systrap_handler’:
indirect_call_table.c:42:1: avís: el control arriba a el final d'una funció que no és void [-Wreturn-type]
COMPILER_PATH=/usr/local/libexec/gcc/pdp11-aout/4.6.4/:/usr/local/libexec/gcc/pdp11-aout/4.6.4/:/usr/local/libexec/gcc/pdp11-aout/:/usr/local/lib/gcc/pdp11-aout/4.6.4/:/usr/local/lib/gcc/pdp11-aout/:/usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/bin/
LIBRARY_PATH=/usr/local/lib/gcc/pdp11-aout/4.6.4/:/usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra'
Comment 1 Jordi Guillaumes Pons 2012-08-16 16:20:46 UTC
The problem seems to be in binutils (gas) instead of gcc. I'm opening a bug in the binutils tracker.