• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision131cb553d6d10412b20cf49bb0e3a5e736a90a36 (tree)
Zeit2020-01-15 22:23:06
AutorJozef Lawrynowicz <jozef.l@mitt...>
CommiterJozef Lawrynowicz

Log Message

MSP430: Fix relocation overflow when using #lo(EXP) macro

gas/ChangeLog:

2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>

* config/tc-msp430.c (CHECK_RELOC_MSP430): Always generate 430X
relocations when the target is 430X, except when extracting part of an
expression.
(msp430_srcoperand): Adjust comment.
Initialize the expp member of the msp430_operand_s struct as
appropriate.
(msp430_dstoperand): Likewise.
* testsuite/gas/msp430/msp430.exp: Run new test.
* testsuite/gas/msp430/reloc-lo-430x.d: New test.
* testsuite/gas/msp430/reloc-lo-430x.s: New test.

include/ChangeLog:

2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>

* opcode/msp430.h (enum msp430_expp_e): New.
(struct msp430_operand_s): Add expp member to struct.

ld/ChangeLog:

2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>

* testsuite/ld-msp430-elf/msp430-elf.exp: Run new test.
* testsuite/ld-msp430-elf/reloc-lo-430x.s: New test.

Ändern Zusammenfassung

Diff

--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,16 @@
1+2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>
2+
3+ * config/tc-msp430.c (CHECK_RELOC_MSP430): Always generate 430X
4+ relocations when the target is 430X, except when extracting part of an
5+ expression.
6+ (msp430_srcoperand): Adjust comment.
7+ Initialize the expp member of the msp430_operand_s struct as
8+ appropriate.
9+ (msp430_dstoperand): Likewise.
10+ * testsuite/gas/msp430/msp430.exp: Run new test.
11+ * testsuite/gas/msp430/reloc-lo-430x.d: New test.
12+ * testsuite/gas/msp430/reloc-lo-430x.s: New test.
13+
114 2020-01-15 Alan Modra <amodra@gmail.com>
215
316 * configure.tgt: Add sparc-*-freebsd case.
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -275,21 +275,21 @@ target_is_430xv2 (void)
275275 return selected_isa == MSP_ISA_430Xv2;
276276 }
277277
278-/* Generate an absolute 16-bit relocation.
279- For the 430X we generate a relocation without linker range checking
280- if the value is being used in an extended (ie 20-bit) instruction,
281- otherwise if have a shifted expression we use a HI reloc.
278+/* Generate an absolute 16-bit relocation, for 430 (!extended_op) instructions
279+ only.
280+ For the 430X we generate a 430 relocation only for the case where part of an
281+ expression is being extracted (e.g. #hi(EXP), #lo(EXP). Otherwise generate
282+ a 430X relocation.
282283 For the 430 we generate a relocation without assembler range checking
283- if we are handling an immediate value or a byte-width instruction. */
284+ if we are handling an immediate value or a byte-width instruction. */
284285
285286 #undef CHECK_RELOC_MSP430
286287 #define CHECK_RELOC_MSP430(OP) \
287288 (target_is_430x () \
288- ? (extended_op \
289- ? BFD_RELOC_16 \
290- : ((OP).vshift == 1) \
291- ? BFD_RELOC_MSP430_ABS_HI16 \
292- : BFD_RELOC_MSP430X_ABS16) \
289+ ? ((OP).expp == MSP_EXPP_ALL \
290+ ? BFD_RELOC_MSP430X_ABS16 \
291+ : ((OP).vshift == 1 \
292+ ? BFD_RELOC_MSP430_ABS_HI16 : BFD_RELOC_16)) \
293293 : ((imm_op || byte_op) \
294294 ? BFD_RELOC_MSP430_16_BYTE : BFD_RELOC_MSP430_16))
295295
@@ -1909,13 +1909,15 @@ msp430_srcoperand (struct msp430_operand_s * op,
19091909 char *h = l;
19101910 int vshift = -1;
19111911 int rval = 0;
1912+ /* Use all parts of the constant expression by default. */
1913+ enum msp430_expp_e expp = MSP_EXPP_ALL;
19121914
19131915 /* Check if there is:
19141916 llo(x) - least significant 16 bits, x &= 0xffff
19151917 lhi(x) - x = (x >> 16) & 0xffff,
19161918 hlo(x) - x = (x >> 32) & 0xffff,
19171919 hhi(x) - x = (x >> 48) & 0xffff
1918- The value _MUST_ be constant expression: #hlo(1231231231). */
1920+ The value _MUST_ be an immediate expression: #hlo(1231231231). */
19191921
19201922 *imm_op = TRUE;
19211923
@@ -1923,31 +1925,37 @@ msp430_srcoperand (struct msp430_operand_s * op,
19231925 {
19241926 vshift = 0;
19251927 rval = 3;
1928+ expp = MSP_EXPP_LLO;
19261929 }
19271930 else if (strncasecmp (h, "#lhi(", 5) == 0)
19281931 {
19291932 vshift = 1;
19301933 rval = 3;
1934+ expp = MSP_EXPP_LHI;
19311935 }
19321936 else if (strncasecmp (h, "#hlo(", 5) == 0)
19331937 {
19341938 vshift = 2;
19351939 rval = 3;
1940+ expp = MSP_EXPP_HLO;
19361941 }
19371942 else if (strncasecmp (h, "#hhi(", 5) == 0)
19381943 {
19391944 vshift = 3;
19401945 rval = 3;
1946+ expp = MSP_EXPP_HHI;
19411947 }
19421948 else if (strncasecmp (h, "#lo(", 4) == 0)
19431949 {
19441950 vshift = 0;
19451951 rval = 2;
1952+ expp = MSP_EXPP_LO;
19461953 }
19471954 else if (strncasecmp (h, "#hi(", 4) == 0)
19481955 {
19491956 vshift = 1;
19501957 rval = 2;
1958+ expp = MSP_EXPP_HI;
19511959 }
19521960
19531961 op->reg = 0; /* Reg PC. */
@@ -1956,6 +1964,7 @@ msp430_srcoperand (struct msp430_operand_s * op,
19561964 __tl = h + 1 + rval;
19571965 op->mode = OP_EXP;
19581966 op->vshift = vshift;
1967+ op->expp = expp;
19591968
19601969 end = parse_exp (__tl, &(op->exp));
19611970 if (end != NULL && *end != 0 && *end != ')' )
@@ -2167,6 +2176,7 @@ msp430_srcoperand (struct msp430_operand_s * op,
21672176 }
21682177 op->mode = OP_EXP;
21692178 op->vshift = 0;
2179+ op->expp = MSP_EXPP_ALL;
21702180 if (op->exp.X_op == O_constant)
21712181 {
21722182 int x = op->exp.X_add_number;
@@ -2275,6 +2285,7 @@ msp430_srcoperand (struct msp430_operand_s * op,
22752285 *h = 0;
22762286 op->mode = OP_EXP;
22772287 op->vshift = 0;
2288+ op->expp = MSP_EXPP_ALL;
22782289 end = parse_exp (__tl, &(op->exp));
22792290 if (end != NULL && *end != 0)
22802291 {
@@ -2348,6 +2359,7 @@ msp430_srcoperand (struct msp430_operand_s * op,
23482359 op->am = (*l == '-' ? 3 : 1);
23492360 op->ol = 1;
23502361 op->vshift = 0;
2362+ op->expp = MSP_EXPP_ALL;
23512363 __tl = l;
23522364 end = parse_exp (__tl, &(op->exp));
23532365 if (end != NULL && * end != 0)
@@ -2382,6 +2394,7 @@ msp430_dstoperand (struct msp430_operand_s * op,
23822394 op->am = 1;
23832395 op->ol = 1;
23842396 op->vshift = 0;
2397+ op->expp = MSP_EXPP_ALL;
23852398 (void) parse_exp (__tl, &(op->exp));
23862399
23872400 if (op->exp.X_op != O_constant || op->exp.X_add_number != 0)
--- a/gas/testsuite/gas/msp430/msp430.exp
+++ b/gas/testsuite/gas/msp430/msp430.exp
@@ -52,4 +52,5 @@ if [expr [istarget "msp430-*-*"]] then {
5252 run_dump_test "attr-430x-large-lower-good"
5353 run_dump_test "attr-430x-large-any-bad"
5454 run_dump_test "attr-430x-large-any-good"
55+ run_dump_test "reloc-lo-430x"
5556 }
--- /dev/null
+++ b/gas/testsuite/gas/msp430/reloc-lo-430x.d
@@ -0,0 +1,5 @@
1+#as: -ml
2+#readelf: -r
3+#...
4+.*R_MSP430_ABS16.*P \+ 0
5+#...
--- /dev/null
+++ b/gas/testsuite/gas/msp430/reloc-lo-430x.s
@@ -0,0 +1,22 @@
1+.text
2+ .balign 2
3+ .global foo
4+ .type foo, @function
5+foo:
6+ MOV.W #lo (P), R8
7+ RETA
8+ .size foo, .-foo
9+
10+ .balign 2
11+ .global main
12+ .type main, @function
13+main:
14+ CALLA #foo
15+.L4:
16+ BRA #.L4
17+ .size main, .-main
18+ .section .bss,"aw",@nobits
19+ .balign 2
20+ .global P
21+P:
22+ .zero 4
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
1+2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>
2+
3+ * opcode/msp430.h (enum msp430_expp_e): New.
4+ (struct msp430_operand_s): Add expp member to struct.
5+
16 2020-01-13 Claudiu Zissulescu <claziss@gmail.com>
27
38 * elf/arc-cpu.def: Update ARC cpu list.
--- a/include/opcode/msp430.h
+++ b/include/opcode/msp430.h
@@ -21,6 +21,18 @@
2121 #ifndef __MSP430_H_
2222 #define __MSP430_H_
2323
24+enum msp430_expp_e
25+{
26+ MSP_EXPP_ALL = 0, /* Use full the value of the expression - default. */
27+ MSP_EXPP_LO, /* Extract least significant word from expression. */
28+ MSP_EXPP_HI, /* Extract 2nd word from expression. */
29+ MSP_EXPP_LLO, /* Extract least significant word from an
30+ immediate value. */
31+ MSP_EXPP_LHI, /* Extract 2nd word from an immediate value. */
32+ MSP_EXPP_HLO, /* Extract 3rd word from an immediate value. */
33+ MSP_EXPP_HHI, /* Extract 4th word from an immediate value. */
34+};
35+
2436 struct msp430_operand_s
2537 {
2638 int ol; /* Operand length words. */
@@ -28,6 +40,9 @@ struct msp430_operand_s
2840 int reg; /* Register. */
2941 int mode; /* Operand mode. */
3042 int vshift; /* Number of bytes to shift operand down. */
43+ enum msp430_expp_e expp; /* For when the operand is a constant
44+ expression, the part of the expression to
45+ extract. */
3146 #define OP_REG 0
3247 #define OP_EXP 1
3348 #ifndef DASM_SECTION
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
1+2020-01-15 Jozef Lawrynowicz <jozef.l@mittosystems.com>
2+
3+ * testsuite/ld-msp430-elf/msp430-elf.exp: Run new test.
4+ * testsuite/ld-msp430-elf/reloc-lo-430x.s: New test.
5+
16 2020-01-15 Alan Modra <amodra@gmail.com>
27
38 * testsuite/ld-powerpc/ambiguousv1b.d: Adjust expected output.
--- a/ld/testsuite/ld-msp430-elf/msp430-elf.exp
+++ b/ld/testsuite/ld-msp430-elf/msp430-elf.exp
@@ -174,6 +174,8 @@ run_ld_link_tests $msp430eithershuffletests
174174 run_ld_link_tests $msp430warntests
175175
176176 run_dump_test valid-map
177+run_ld_link_tests {{ "Check no reloc overflow with #lo and data in the upper region"
178+ "-m msp430X" "" "" {reloc-lo-430x.s} {} "reloc-lo-430x"}}
177179
178180 # Don't run data region tests if a data region is specified
179181 if {[string match "*-mdata-region*" [board_info [target_info name] multilib_flags]]} {
--- /dev/null
+++ b/ld/testsuite/ld-msp430-elf/reloc-lo-430x.s
@@ -0,0 +1,22 @@
1+.text
2+ .balign 2
3+ .global foo
4+ .type foo, @function
5+foo:
6+ MOV.W #lo (P), R8
7+ RETA
8+ .size foo, .-foo
9+
10+ .balign 2
11+ .global main
12+ .type main, @function
13+main:
14+ CALLA #foo
15+.L4:
16+ BRA #.L4
17+ .size main, .-main
18+ .section .bss,"aw",@nobits
19+ .balign 2
20+ .global P
21+P:
22+ .zero 4