When building with SDCC, v1.5.x outputs non-printable chars in the COFF file which causes MPLABX to fail loading the resulting binary. See examples below, extracted with gpov:
v1.4.x - ok
COFF File and Optional Headers COFF version 0x1240: MICROCHIP_MAGIC_v2 Processor Type 16f887 Time Stamp 05-05-2017 21:59:13 Number of Sections zu Number of Symbols 308 Characteristics 0x2 File is executable. Section Header Name sharebank Physical address 0x70 Virtual address 0x70 Size of Section 16 Number of Relocations zu Number of Line Numbers zu Flags 0x5080 Uninitialized data. Absolute. Overlaid with other sections from different objects modules.
v.1.5.0-1 - ERROR in the first section name
COFF File and Optional Headers COFF version 0x1240: MICROCHIP_MAGIC_v2 Processor Type 16f887 Time Stamp 05-05-2017 22:02:31 Number of Sections zu Number of Symbols 233 Characteristics 0x2 File is executable. Section Header Name U Physical address 0x70 Virtual address 0x70 Size of Section 16 Number of Relocations zu Number of Line Numbers zu Flags 0x5080 Uninitialized data. Absolute. Overlaid with other sections from different objects modules.
build v1.5.1.1301 - ERROR - first section header
COFF File and Optional Headers COFF version 0x1240: MICROCHIP_MAGIC_v2 Processor Type 16f887 Time Stamp 05-05-2017 22:24:29 Number of Sections zu Number of Symbols 233 Characteristics 0x2 File is executable. Section Header Name Physical address 0x70 Virtual address 0x70 Size of Section 16 Number of Relocations zu Number of Line Numbers zu Flags 0x5080 Uninitialized data. Absolute. Overlaid with other sections from different objects modules.
Also the number of symbols is rather reduced in v1.5.x, maybe due to linker optimizations?
Diff:
gpov --> gpvo
Which operating system did the compile of gputils? What was the compiler? Clang, gcc or something else? For something is wrong:
"Number of Relocations zu"
This is in the source code:
printf("Number of Relocations %zu\n", Section->relocation_list.num_nodes);
It seems that the C compiler does not know the "%zu" formatting string.
This may be due to this: gplink String Table Optimisation
Molnár Károly
Last edit: Molnár Károly 2017-05-07
Diff:
I am just using the prebuilt binaries from this site - not homebuilt.
My test environment is Win10 x64 and probuilt SDCC v3.6.0
Probably only windows binary is wrong because no such bugs have been reported so far. I've made an improved version, but I'm not sure it's all right. [r1303]
gputils-20170507-1303-setup.exe
Related
Commit: [r1303]
Thanks for the fast reply and fix.
Actually, there are some issues, they have just not been reported here, or are not obvious to the end users.
Like this www.microchip.com/forums/m987524.aspx
Just tried the 1303 build. Now i get an failed assertion. See below.
Thanks in advanced
Interesting, if I runs on Linux, then there is nothing wrong with it. I still have to work with it.
Károly
Let me know if you need anything.
Patrick
Thank you for the good intent, but I can solve the testing. :-) I just need a little time.
Károly
ok, just took a look at the assert.
your commit 1302->1303 in gpcod.c:
the added sbprintf format string will always be 8 chars long - same as Pascal_max_size in the following assert that it should be shorter than.
If I remove the trailing \n in the format string, the assert goes away.
Now it just produces an invalid? coff file. MPLABX can't load it.
My best guess is empty sections with uninitialized names (shows up with random chars/values)
I was forgetful and left it there the \n character. I've fixed this in the [r1304] version.
Related
Commit: [r1304]
Great, thanks. Assert fixed.
But the COFF file is still broken. MPLABX will not load it.
Some section names contains random chars. Only for uninitialized/empty sections?
I need an example which generates the error.
See attached zipfile
The asm file is generated by sdcc.
commands:
Output from mplabx using sdcc 3.6.0 and gputils1.5.x
Hope it helps
Just found this comment in a MPLABX SDK file called "CoffSectionHeader.java":
Could that explain the problem?
From the libgputils/gpcoff.h file:
This is not seven, but eight. So far nobody was troubled this difference, at least nobody indicated that it would cause a mistake. In turn it has been so for years.
From the libgputils/gpreadobj.c file:
From the libgputils/gpwriteobj.c file:
I ran the following commands:
gpvo main.o > main.o.dump
wine gpvo.exe main.o > main.o.txt
diff -up --strip-trailing-cr main.o.txt main.o.dump > main.o.dump.diff
Content of the main.o.dump.diff file:
It's almost the same.
Which program was produced the main.txt file? It is not like the output of the gpvo.exe program.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I ran the command
gpvo.exe main.cof > main.txt
This is the COFF file produced by the linker - required by MPLABX in order to show memory usage in non-debug builds. The output from the assembler (main.o) looks just fine, but the output from the linker (main.cof) looks strange.
It turned out now that we both was thinking about other things. :-( The Microchip and gputils treat slightly differently the coff format. Therefore the gpvo is not capable of correctly processed by Microchip's coff files. The same is true vice versa also. I assume that the format was once uniform, but Microchip changed something. It seems that few and rarely use together the mplabx and gputils, because so far there was no such complaint.
I traced the coff-file problem to first appear in build 1219 (between 1217 and 1219). One of the things changed, apart from a lot of renaming, is massive changes to the libgputils\gpcoffgen.c and related files. Massive changes, probably related to the introduction of the -b flag on gplink.
I'm looking for the bug, but lately I have little time. I temporarily put a printf call on the scanning process. Then I did a debug list with the following command line:
gpvo main.cof > main.cof.dump-1.5.2
So the list starts:
It appears that main.cof stores the strings differently as the main.o file. The internal addresses point to different location.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Yes, something happend to the coff output from the linker. v1.4.x works fine, so MPLABX users (all 5 of us) will most likely just use that version for now.
I looked also with a very old (0.13.7) gpvo version:
gpvo main.cof > main.cof.dump-0.13.7
It behaves also the same as the present versions.
Yes, looks wrong. But maybe the problem is not with main.o, but with one of the libraries that gets linked in. (libsdcc.lib or pic16f887.lib)? What do they look like inside?
Btw, i have been working a bit on a MPLABX plugin for gputils, so gpasm can be selected as a build tool, just like mpasm or any other compiler. Is it of any interest?
It can be found on https://github.com/mc6pac/toolchainGPUTILS
It is in a very rough preliminary version, but somewhat functional. No binaries yet.
This error should be search in libgputils.
I encourage you to continue the development.
This is a bugfix:
gputils-src-20170702-1309.tar.bz2
gputils-20170702-1309-setup.exe
Please try it out.
Károly