Compile this code for 32-bit using -fPIC:

int fn(int i) {
  switch (i)
    {
    case 0:
      return 0;
    case 1:
      return 1;
    case 2:
      return 2;
    case 3:
      return 3;
    case 4:
      return 4;
    case 5:
      return 5;
    case 6:
      return 6;
    case 7:
      return 7;
    case 8:
      return 8;
    case 9:
      return 9;
    default:
      return 10;
    }
}

When I do that, I get a switch table in .rodata.  The switch table has entries
like
        .long   ....@gotoff
Since .L3 is defined in the .text section, this causes the assembler to emit a
R_386_GOTOFF relocation against the local symbol .L3.  This causes the local
symbol to be emitted into the symbol table.  That is undesirable.  It would be
better to write out something like
        .long   f...@gotoff+(.L3-fn)
which would not require any additional entries in the symbol table.


-- 
           Summary: 32-bit x86 switch table refers to local symbols with -
                    fPIC
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43025

Reply via email to