<< Back to previous view

[PCC-369] size of array is output as zero Created: 05/Jul/11  Updated: 05/Jul/11

Status: Resolved
Project: pcc
Component/s: C frontend
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Iain Hibbert Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: NetBSD/i386


 Description   
defined array objects are output as size zero, causing errors when linking
from another module, eg

int foo[] = { 1, 2, 3 };

when compiled with pcc -S produces code

        .data
        .align 4
        .globl foo
        .type foo,@object
        .size foo,0 ; <-----
foo:
        .long 1
        .long 2
        .long 3
        .ident "PCC: pcc 1.1.0.DEVEL 20110701 for netbsd-i386"

this is not a problem in itself, but when this is built as a shared object and
linked from an external program, ld fails, eg

% cat foo.c
int foo[] = { 1, 2, 3 };
% pcc -shared foo.c -o foo.so
% cat bar.c
extern int foo[];

int main(int ac, char *av)
{
        return foo[1];
}
% pcc bar.c foo.so -o bar
ld: dynamic variable `foo' is zero size
ld: /tmp/ctm.16459c(.text+0x7): unresolvable R_386_32 relocation against symbol `foo'
ld: final link failed: Nonrepresentable section on output


 Comments   
Comment by Anders Magnusson [ 05/Jul/11 10:19 PM ]
Fixed by reorder calculation of array size and printing out the symbol names.
Generated at Wed Nov 26 23:54:44 CET 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.