GCC - General Discussion and Assistance - CHDK Forum supplierdeeply

GCC

  • 5 Replies
  • 510 Views
*

Offline philmoz

  • *****
  • 3107
    • Photos
GCC
« on: 30 / June / 2017, 23:14:09 »
Advertisements
  In case anyone want to try it, I've added support for building with ARM GCC v5 to the 1.5 trunk.


Currently there is one issue where functions/variables only referenced in inline assembly code may get optimised out of the C code (e.g. S80 won't build).
Other than that 5.4 seems to work ok on my cameras, can't see any major improvements for CHDK though.


Phil.

« Last Edit: 30 / June / 2017, 23:17:12 by philmoz »
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline philmoz

  • *****
  • 3107
    • Photos
Re: GCC
« Reply #1 on: 20 / October / 2017, 21:04:23 »
Word of caution - I tried building with GCC6 and it currently breaks CHDK.


Although it builds, the result won't run.
It seems that GCC6 generates 'LDR PC, LR' instructions as function exit instead of 'BX LR'.
This crashes if returning to a Thumb function from and ARM function.


There may be option(s) to fix this; but a quick search did not find anything obvious.


Phil.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

*

Offline rudi

  • ***
  • 126
  • A590IS_101B, SX260HS_100B
Re: GCC 5
« Reply #2 on: 06 / June / 2019, 14:22:00 »
I get also errors for S80 and M10 on building trunk with GCC 5.5.0 toolchain on WSL. GCC 5 only tested on SX260. My solution:
Code: [Select]
Index: platform/m10/sub/110d/movie_rec.c
===================================================================
--- platform/m10/sub/110d/movie_rec.c    (revision 5226)
+++ platform/m10/sub/110d/movie_rec.c    (working copy)
@@ -505,6 +505,20 @@
 "loc_fc0fe176:\n"
 "    strh    r2, [r7, #0x10]\n"
 "    b       loc_fc0fe188\n"
+// 'springboard table' from line 580
+"loc_fc0fe20c:\n"
+"    b       loc_fc0fe34c\n"
+"loc_fc0fe20e:\n"
+"    b       loc_fc0fe324\n"
+"loc_fc0fe210:\n"
+"    b       loc_fc0fe312\n"
+"loc_fc0fe212:\n"
+"    b       loc_fc0fe2c0\n"
+"loc_fc0fe214:\n"
+"    b       loc_fc0fe2ce\n"
+"loc_fc0fe216:\n"
+"    b       loc_fc0fe2e8\n"
+// 'springboard table' end
 "loc_fc0fe17a:\n"
 "    movw    r2, #0x602\n"
 "loc_fc0fe17e:\n"
@@ -563,18 +577,7 @@
 "    movw    lr, #0x780\n"
 "    cmp     r3, lr\n"
 "    b       loc_fc0fe218\n"
-"loc_fc0fe20c:\n"
-"    b       loc_fc0fe34c\n"
-"loc_fc0fe20e:\n"
-"    b       loc_fc0fe324\n"
-"loc_fc0fe210:\n"
-"    b       loc_fc0fe312\n"
-"loc_fc0fe212:\n"
-"    b       loc_fc0fe2c0\n"
-"loc_fc0fe214:\n"
-"    b       loc_fc0fe2ce\n"
-"loc_fc0fe216:\n"
-"    b       loc_fc0fe2e8\n"
+// move 'springbord table' to line 508; this position is too far for .byte(offset)
 "loc_fc0fe218:\n"
 "    bne     loc_fc0fe306\n"
 "    add.w   r4, r4, #0x1c\n"
Index: platform/m10/sub/110f/movie_rec.c
===================================================================
--- platform/m10/sub/110f/movie_rec.c    (revision 5226)
+++ platform/m10/sub/110f/movie_rec.c    (working copy)
@@ -505,6 +505,20 @@
 "loc_fc0fe176:\n"
 "    strh    r2, [r7, #0x10]\n"
 "    b       loc_fc0fe188\n"
+// 'springboard table' from line 580
+"loc_fc0fe20c:\n"
+"    b       loc_fc0fe34c\n"
+"loc_fc0fe20e:\n"
+"    b       loc_fc0fe324\n"
+"loc_fc0fe210:\n"
+"    b       loc_fc0fe312\n"
+"loc_fc0fe212:\n"
+"    b       loc_fc0fe2c0\n"
+"loc_fc0fe214:\n"
+"    b       loc_fc0fe2ce\n"
+"loc_fc0fe216:\n"
+"    b       loc_fc0fe2e8\n"
+// 'springboard table' end
 "loc_fc0fe17a:\n"
 "    movw    r2, #0x602\n"
 "loc_fc0fe17e:\n"
@@ -563,18 +577,7 @@
 "    movw    lr, #0x780\n"
 "    cmp     r3, lr\n"
 "    b       loc_fc0fe218\n"
-"loc_fc0fe20c:\n"
-"    b       loc_fc0fe34c\n"
-"loc_fc0fe20e:\n"
-"    b       loc_fc0fe324\n"
-"loc_fc0fe210:\n"
-"    b       loc_fc0fe312\n"
-"loc_fc0fe212:\n"
-"    b       loc_fc0fe2c0\n"
-"loc_fc0fe214:\n"
-"    b       loc_fc0fe2ce\n"
-"loc_fc0fe216:\n"
-"    b       loc_fc0fe2e8\n"
+// move 'springbord table' to line 508; this position is too far for .byte(offset)
 "loc_fc0fe218:\n"
 "    bne     loc_fc0fe306\n"
 "    add.w   r4, r4, #0x1c\n"
Index: platform/s80/sub/100g/boot.c
===================================================================
--- platform/s80/sub/100g/boot.c    (revision 5226)
+++ platform/s80/sub/100g/boot.c    (working copy)
@@ -148,7 +148,7 @@
     );
 }
 
-static int jogdial_is_stopped = 0;
+int jogdial_is_stopped = 0;
 
 void set_jogdial_is_stopped () {
     extern int jogdial_stopped; // from kbd.c
Index: platform/s80/sub/101b/boot.c
===================================================================
--- platform/s80/sub/101b/boot.c    (revision 5226)
+++ platform/s80/sub/101b/boot.c    (working copy)
@@ -148,7 +148,7 @@
     );
 }
 
-static int jogdial_is_stopped = 0;
+int jogdial_is_stopped = 0;
 
 void set_jogdial_is_stopped () {
     extern int jogdial_stopped; // from kbd.c
This patch is not testet on S80 or M10!
A GCC 4 build identical DISKBOOT.BIN's for S80 with and without this patch.
I don't know why GCC 4 assembler don't rise also an error for M10.

rudi

*

Offline srsa_4c

  • ******
  • 3906
Re: GCC 5
« Reply #3 on: 06 / June / 2019, 18:10:48 »
I don't know why GCC 4 assembler don't rise also an error for M10.
The jumptable in question uses the tbb instruction (offsets are expressed on one byte). When compiled on gcc 4.9, the table looks like this:
Code: [Select]
003d91ee <branchtable_fc0fe01a>:
  3d91ee: 19fd      .short 0x19fd
  3d91f0: fbfc0b71 .word 0xfbfc0b71
  3d91f4: 717284a0 .word 0x717284a0
  3d91f8: f9fa7171 .word 0xf9fa7171
  3d91fc: 594433f8 .word 0x594433f8
  3d9200: b6717171 .word 0xb6717171
The largest byte is 0xfd. Apparently, the gcc 5.5 toolchain either uses wide encoding for some instructions, or it puts a literal table in that region, which introduces offsets that the tbb based jumptable can't handle.

Can you show the error you're getting when compiling for s80?

Also, does anyone else using gcc 5 or higher experience this (I mean, could this be a toolchain source configuration issue)?


*

Offline rudi

  • ***
  • 126
  • A590IS_101B, SX260HS_100B
Re: GCC
« Reply #4 on: 06 / June / 2019, 18:54:58 »
Thank you for your Infos.
It is a cross compiler and not a toolchain. my fault. I use the same cross compilers build script for building gcc 4.8.3 in 2015.

S80 error message:
Code: [Select]
../../../../platform/s80/sub/100g/libplatformsub.a(boot.o): In function `loc_FF82898C':boot.c:(.text+0x3f0): undefined reference to `jogdial_is_stopped'
collect2: error: ld returned 1 exit status
../../../makefile_sub.inc:67: recipe for target 'main.elf' failed
M10 error message:
Code: [Select]
movie_rec.c -> movie_rec.o
/tmp/ccTpDW5H.s: Assembler messages:
/tmp/ccTpDW5H.s:610: Error: value of 257 too large for field of 1 bytes at 1138
/tmp/ccTpDW5H.s:614: Error: value of 256 too large for field of 1 bytes at 1142
../../../makefile_sub.inc:44: recipe for target 'movie_rec.o' failed
The largest byte is 0xfd.
Calculated on loc_addresses? But there are additional code for chdk extensions eg. video bitrate.
Also, does anyone else using gcc 5 or higher experience this (I mean, could this be a toolchain source configuration issue)?
I will looking for.

rudi

*

Offline srsa_4c

  • ******
  • 3906
Re: GCC
« Reply #5 on: 12 / June / 2019, 12:22:40 »
I forgot to answer this, sorry.
It is a cross compiler and not a toolchain. my fault. I use the same cross compilers build script for building gcc 4.8.3 in 2015.
Do the Windows versions of these toolchains have similar issues? I mean mostly the 5.0 series.
Also, what package versions did you use when building your cross compiler? (gcc and its dependencies, binutils ?)
Quote
S80 error message:
Code: [Select]
../../../../platform/s80/sub/100g/libplatformsub.a(boot.o): In function `loc_FF82898C':boot.c:(.text+0x3f0): undefined reference to `jogdial_is_stopped'
collect2: error: ld returned 1 exit status
../../../makefile_sub.inc:67: recipe for target 'main.elf' failed
That sounds like the jogdial_is_stopped variable getting optimized out when it's static.
Quote
M10 error message:
Code: [Select]
movie_rec.c -> movie_rec.o
/tmp/ccTpDW5H.s: Assembler messages:
/tmp/ccTpDW5H.s:610: Error: value of 257 too large for field of 1 bytes at 1138
/tmp/ccTpDW5H.s:614: Error: value of 256 too large for field of 1 bytes at 1142
../../../makefile_sub.inc:44: recipe for target 'movie_rec.o' failed
That's what I was suspecting.
Quote
Calculated on loc_addresses? But there are additional code for chdk extensions eg. video bitrate.
The additions are outside the reach of that jumptable.

I would like to avoid changing that assembly code, if possible. It comes from disassembling a piece of firmware and making changes to it would make it harder to follow in case someone wanted to port the movie support code.