I attempted to use 'gplink -O2' to remove unused code from one of my projects, but found that it did almost nothing. 'gplink -O2' removes only sections that has no relocations into it. Not even sections where all the relocations originate from the same section. A section like the following will never be eliminated:
test.code CODE GOBAL test test: goto $+1 return
That includes ANY section that contains loops or branches (most of the functions I wanted to optimize away)
I made the following change in gplink and it seems to work:
=================================================================== --- gputils/libgputils/gpcoffopt.c (revision 1108) +++ gputils/libgputils/gpcoffopt.c (arbetskopia) @@ -71,9 +71,10 @@ /* mark all sections that relocations point to as unused */ relocation = section->relocations; while (relocation != NULL) { - if (relocation->symbol->section) - relocation->symbol->section->is_used = true; - else + if (relocation->symbol->section) { + if (relocation->symbol->section != section) + relocation->symbol->section->is_used = true; + } else gp_warning("relocation symbol %s has no section", relocation->symbol->name); relocation = relocation->next; ===================================================================
I must admit that I don't understand the linker in general enough to know if this change breaks something elsewhere.
Anonymous
I will to watch, the modification may cause any error?
Károly
Is not good the solution. The enclosed example shows it that, the code disappears totally. See: program.dis
Károly
I had no problem with my project, but I had a
in my program, and since that section had an absolute address it was kept, and anchored the rest of the code. Is it actually realistic to have no absolute sections? How do you know what ends up on at the reset vector?
Of this really needs to exist.
Please give me an example code that allows you to present the result of the modification.
Károly
Simple example that shows the difference:
Good this solution, is now included in the new svn #1110 code. I hope that in the future will neither cause an error. Thank you for your contribution.
Károly
The modified gputils:
svn [r1111]
gputils-20141101-1111-setup.exe
gputils-src-20141101-1111.tar.gz
Related
Commit: [r1111]
Last edit: Molnár Károly 2016-02-15