Skip to content

MC-COFF: Don't emit local storage with .bss$linkonce #8726

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 8354
Resolution FIXED
Resolved on Aug 11, 2014 12:36
Version trunk
OS Windows XP
Blocks llvm/llvm-bugzilla-archive#8390
Reporter LLVM Bugzilla Contributor
CC @rnk

Extended Description

.bss$linkonce_foobar would be unified by linker.
static and anonymous variables should not emitted to linkonce.

//////// foo.cc
int foo;
static int bar;

namespace {
int qux;
static int quux;
}

void fooset(int a0, int a1, int a2, int a3)
{
foo = a0;
bar = a1;
qux = a2;
quux = a3;
}

int fooget()
{
return foo + bar + qux + quux;
}

//////// bar.cc
extern int foo;
static int bar;

namespace {
int qux;
static int quux;
}

void barset(int a0, int a1, int a2, int a3)
{
foo = a0;
bar = a1;
qux = a2;
quux = a3;
}

int barget()
{
return foo + bar + qux + quux;
}

========

$ clang++ -O3 -S -emit-llvm foo.cc -o foo.ll
(snip)
@​foo = global i32 0, align 4
@​_ZL3bar = internal global i32 0, align 4
@​_ZN12_GLOBAL__N_13quxE = internal global i32 0, align 4
@​_ZN12_GLOBAL__N_1L4quuxE = internal global i32 0, align 4

$ clang++ -O3 -S -emit-llvm bar.cc -o bar.ll
(snip)
@​foo = external global i32
@​_ZL3bar = internal global i32 0, align 4
@​_ZN12_GLOBAL__N_13quxE = internal global i32 0, align 4
@​_ZN12_GLOBAL__N_1L4quuxE = internal global i32 0, align 4

========

$ llc -filetype=obj foo.ll
$ llc -filetype=obj bar.ll
$ ld foo.o bar.o -o foobar.exe

$ objdump -h foobar.exe
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000000a8 00401000 00401000 00000400 24
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000004 00402000 00402000 00000600 2
2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 0000000c 00403000 00403000 00000000 22
ALLOC
3 .idata 00000014 00404000 00404000 00000800 2
2
CONTENTS, ALLOC, LOAD, DATA

!!! size of .bss should be 0x18(4 * 6)!

$ nm -n --demangle foobar.exe

00402000 D data_start_
00402000 D foo
00402004 D data_end_
00403000 B bss_start_
00403000 B bss_end_
00403000 b .bss$linkonce__ZL3bar
00403000 b bar
00403004 b .bss$linkonce__ZN12_GLOBAL__N_13quxE
00403004 b (anonymous namespace)::qux
00403008 b .bss$linkonce__ZN12_GLOBAL__N_1L4quuxE
00403008 b (anonymous namespace)::quux

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions