Skip to content

Commit eea2517

Browse files
mikpeJeffreyALaw
authored andcommitted
[PATCH] wrong code on m68k with -mlong-jump-table-offsets and -malign-int (PR target/112413)
On m68k the compiler assumes that the PC-relative jump-via-jump-table instruction and the jump table are adjacent with no padding in between. When -mlong-jump-table-offsets is combined with -malign-int, a 2-byte nop may be inserted before the jump table, causing the jump to add the fetched offset to the wrong PC base and thus jump to the wrong address. Fixed by referencing the jump table via its label. On the test case in the PR the object code change is (the moveal at 16 is the nop): a: 6536 bcss 42 <f+0x42> c: e588 lsll #2,%d0 e: 203b 0808 movel %pc@(18 <f+0x18>,%d0:l),%d0 - 12: 4efb 0802 jmp %pc@(16 <f+0x16>,%d0:l) + 12: 4efb 0804 jmp %pc@(18 <f+0x18>,%d0:l) 16: 284c moveal %a4,%a4 18: 0000 0020 orib #32,%d0 1c: 0000 002c orib #44,%d0 Bootstrapped and tested on m68k-linux-gnu, no regressions. Note: I don't have commit rights to I would need assistance applying this. PR target/112413 gcc/ * config/m68k/linux.h (ASM_RETURN_CASE_JUMP): For TARGET_LONG_JUMP_TABLE_OFFSETS, reference the jump table via its label. * config/m68k/m68kelf.h (ASM_RETURN_CASE_JUMP): Likewise. * config/m68k/netbsd-elf.h (ASM_RETURN_CASE_JUMP): Likewise.
1 parent f5fc001 commit eea2517

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

gcc/config/m68k/linux.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ along with GCC; see the file COPYING3. If not see
102102
if (ADDRESS_REG_P (operands[0])) \
103103
return "jmp %%pc@(2,%0:l)"; \
104104
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
105-
return "jmp %%pc@(2,%0:l)"; \
105+
return "jmp %%pc@(%l1,%0:l)"; \
106106
else \
107107
return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \
108108
} \
109109
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
110-
return "jmp %%pc@(2,%0:l)"; \
110+
return "jmp %%pc@(%l1,%0:l)"; \
111111
else \
112112
return "jmp %%pc@(2,%0:w)"; \
113113
} while (0)

gcc/config/m68k/m68kelf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ along with GCC; see the file COPYING3. If not see
5959
if (ADDRESS_REG_P (operands[0])) \
6060
return "jmp %%pc@(2,%0:l)"; \
6161
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
62-
return "jmp %%pc@(2,%0:l)"; \
62+
return "jmp %%pc@(%l1,%0:l)"; \
6363
else \
6464
return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \
6565
} \
6666
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
67-
return "jmp %%pc@(2,%0:l)"; \
67+
return "jmp %%pc@(%l1,%0:l)"; \
6868
else \
6969
return "jmp %%pc@(2,%0:w)"; \
7070
} while (0)

gcc/config/m68k/netbsd-elf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ while (0)
137137
if (ADDRESS_REG_P (operands[0])) \
138138
return "jmp %%pc@(2,%0:l)"; \
139139
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
140-
return "jmp %%pc@(2,%0:l)"; \
140+
return "jmp %%pc@(%l1,%0:l)"; \
141141
else \
142142
return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \
143143
} \
144144
else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \
145-
return "jmp %%pc@(2,%0:l)"; \
145+
return "jmp %%pc@(%l1,%0:l)"; \
146146
else \
147147
return "jmp %%pc@(2,%0:w)"; \
148148
} while (0)

0 commit comments

Comments
 (0)