public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/56880] New: R_X86_64_COPY bug
@ 2013-04-08 16:44 fredrickprashanth at gmail dot com
  2013-04-08 21:57 ` [Bug c/56880] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: fredrickprashanth at gmail dot com @ 2013-04-08 16:44 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56880
           Summary: R_X86_64_COPY bug
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fredrickprashanth@gmail.com


A struct with zero length array is defined in a shared library as a global
data.
A binary links with this shared library and accesses the struct.
Because of copy relocation semantics, the binary linking with that
library sees(correctly) only the portion of the struct without the
zero length array.
We understand that it is due to the wrong or apparent size calculation
of the struct by GCC and using copy relocation semantics to resolve this
shared symbol is causing this problem.

We saw this bug also on ARM with R_ARM_COPY.


test_misc.h:
#ifndef __TEST_MISC_H__
#define __TEST_MISC_H__
struct test_array {
int array_len;
int array[];
};

void print_array(struct test_array *);
#endif

test_lib.c:
#include "test_misc.h"
#include <stdio.h>
struct test_array test_dynamic = {
6,
{1, 2, 3, 4, 5, 6},
};

void
print_array(struct test_array *a) {
int i;
for (i = 0; i<a->array_len; i++) {
printf("%d\n", a->array[i]);
}
}

test_misc.c:
#include "test_misc.h"
extern struct test_array test_dynamic;
int
main() {
print_array(&test_dynamic);
return 0;
}

Makefile:
all: test_misc.bin

test_misc.bin: test_misc.o libtest.so
cc test_misc.o libtest.so -o test_misc.bin

libtest.so: test_lib.o
cc -shared -Wl,-soname,libtest.so -o libtest.so test_lib.o

test_lib.o: test_lib.c
cc -fPIC -o test_lib.o -c test_lib.c
.PHONY: clean
clean:
rm -rf test_misc.bin
rm -rf libtest.so
rm -rf *.o


$ LD_LIBRARY_PATH=. ./test_misc.bin
0
0
0
0
0
0




This seems to be a bug in GCC:


        .globl  test_dynamic
        .data
        .align 4
        .type   test_dynamic, @object
        .size   test_dynamic, 4
test_dynamic:
        .long   6
        .long   1
        .long   2
        .long   3
        .long   4
        .long   5
        .long   6


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/56880] R_X86_64_COPY bug
  2013-04-08 16:44 [Bug c/56880] New: R_X86_64_COPY bug fredrickprashanth at gmail dot com
@ 2013-04-08 21:57 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-04-08 21:57 UTC (permalink / raw)
  To: gcc-bugs


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-04-08 21:57:03 UTC ---
Dup of bug 28865.

*** This bug has been marked as a duplicate of bug 28865 ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-08 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-08 16:44 [Bug c/56880] New: R_X86_64_COPY bug fredrickprashanth at gmail dot com
2013-04-08 21:57 ` [Bug c/56880] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).