Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 36047
Product:  
Component:  
Status: UNCONFIRMED
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: gcc@breakpoint.cc
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 36047 depends on: Show dependency tree
Show dependency graph
Bug 36047 blocks:

Additional Comments:






Mark bug as waiting for feedback



    

    

View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2008-04-25 15:04
bigeasy@ayoka:~/cc$ echo 'int main(void) { return 0; }' > file.c
bigeasy@ayoka:~/cc$ m68k-linux-gnu-gcc -o file file.c -static -pg
/tmp/ccw33VYP.o: In function `main':
file.c:(.text+0x6): relocation truncated to fit: R_68K_PC16 against `.data'
collect2: ld returned 1 exit status

It works fine with a small binary (without -static).
I don't really know what the label is used for. I patched my gcc with:
|--- a/gcc/config/m68k/linux.h
|+++ b/gcc/config/m68k/linux.h
|@@ -143,7 +143,6 @@ along with GCC; see the file COPYING3.
| #undef FUNCTION_PROFILER
| #define FUNCTION_PROFILER(FILE, LABELNO) \
| {                                                                 \
|-  asm_fprintf (FILE, "\tlea (%LLP%d,%Rpc),%Ra1\n", (LABELNO));            \
|   if (flag_pic)                                                           \
|     fprintf (FILE, "\tbsr.l _mcount@PLTPC\n");                            \
|   else                                                                    \
|--- a/gcc/config/m68k/m68k.h
|+++ b/gcc/config/m68k/m68k.h
|@@ -576,7 +576,7 @@ extern enum reg_class regno_reg_class[];
| #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) 0
|
| #define FUNCTION_PROFILER(FILE, LABELNO)  \
|-  asm_fprintf (FILE, "\tlea %LLP%d,%Ra0\n\tjsr mcount\n", (LABELNO))
|+  asm_fprintf (FILE, "\tjsr mcount\n", (LABELNO))
|
| #define EXIT_IGNORE_STACK 1
|

I'm not using glibc's mcount function but my own in which I unwind the stack in
order to obtain caller's address (that's the purpose of the label I guess).

I checked gcc-core-4.3.0.tar.bz2 and the two lea lines are unchanged so the bug
should be still there. 

Now how do we fix this? Removing the label or allowing larger distances?

------- Comment #1 From gcc@breakpoint.cc 2008-07-24 19:48 -------
Does anybody care about this bug?

------- Comment #2 From Maxim Kuvyrkov 2009-03-16 11:35 -------
Would you please attach a preprocessed testcase so one can reproduce the
problem.

------- Comment #3 From gcc@breakpoint.cc 2009-04-22 18:41 -------
Wasn't 

# echo 'int main(void) { return 0; }' > file.c

not enough or did you overlook that part? 

The -E output is pretty much the same, it is:

$ cat test.i 
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
int main(void)
{
 return 0;
}


---
The -S output (I guess you meant that) would be:

$ m68k-linux-gnu-gcc -o test.S test.c -static -pg -S && cat test.S 
#NO_APP
        .file   "test.c"
        .text
        .align  2
        .globl  main
        .type   main, @function
main:
        link.w %fp,#0
        .data
        .align  2
.LP2:
        .long   0
        .text
        lea (.LP2,%pc),%a1
        jbsr _mcount
        clr.l %d0
        unlk %fp
        rts
        .size   main, .-main
        .ident  "GCC: (Sourcery G++ Lite 4.3-43) 4.3.2"
        .section        .note.GNU-stack,"",@progbits
---- 

And my rec for the fix was to get rid of the lea before the branch to the
_mcount call. However someone might need it, I'm not sure.

------- Comment #4 From Maxim Kuvyrkov 2009-11-04 16:57 -------
It appears that 'lea' serves some compatibility purpose.  The code is there
since 1995.

Recent GLIBC defines _mcount as
void
_mcount (void)
{
  mcount_internal ((u_long)
                   __builtin_extract_return_addr (__builtin_return_address
                                                  (1)),
                   (u_long)
                   __builtin_extract_return_addr (__builtin_return_address
                                                  (0)));
}
so the value of %a1 is unused.  Newlib and uClibc don't define _mcount for m68k
at all.

Andreas, I suggest simply removing the 'lea'; they seem to be no users for it.

Alternatively, for the !PIC case we may use 'lea <label>, %a1' (no pc-relative
relocation) and for the PIC case use a longer sequence, something like: 'move.l
#<label>@PC32, %a1\n add.l (-4, %pc), %a1'.

------- Comment #5 From Maxim Kuvyrkov 2009-11-19 10:09 -------
gcc@breakpoint.cc,

Would you please submit your patch to gcc-patches@gcc.gnu.org.  Only the
linux.h version of FUNCTION_PROFILER causes problems, you can leave the m68k.h
version as is.

Thanks.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug