Menu

#275 gplink -O2 almost useless

None
closed-fixed
None
1
2016-04-13
2014-10-20
No

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.

Discussion

  • Molnár Károly

    Molnár Károly - 2014-10-23

    I will to watch, the modification may cause any error?

    Károly

     
  • Molnár Károly

    Molnár Károly - 2014-10-23
    • assigned_to: Molnár Károly
     
  • Molnár Károly

    Molnár Károly - 2014-10-25

    Is not good the solution. The enclosed example shows it that, the code disappears totally. See: program.dis

    Károly

     
  • Daniel Anderberg

    I had no problem with my project, but I had a

    _reset_vector.code CODE 0
        goto    _init
    

    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?

     
  • Molnár Károly

    Molnár Károly - 2014-10-27

    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

     
  • Daniel Anderberg

    Simple example that shows the difference:

     
  • Molnár Károly

    Molnár Károly - 2014-11-01

    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

     
  • Molnár Károly

    Molnár Károly - 2014-12-20
    • status: open --> closed
     
  • Molnár Károly

    Molnár Károly - 2016-04-13
    • status: closed --> closed-fixed
     

Anonymous
Anonymous

Add attachments
Cancel