Commit d9f1f9fc by Jim Stichnoth

Subzero: Fix lit and cross tests broken in f8b4cc84.

1. The data symbol __Sz_block_profile_info should never be mangled (for cross tests), similar to runtime helper calls. Add a SuppressMangling override for such variable declarations. 2. When cross tests contain more than one translated object file, we end up with multiple definitions of __Sz_block_profile_info . Work around this by making that symbol weak. 3. Don't try to attach global inits to an EmitterWorkItem that represents a translation error. 4. Update one lit test to reflect the additional profiling value in the data section. 5. Update one lit test to reflect that global initializers are emitted at the end instead of the beginning. The check-unit test is still broken and will be fixed in a separate CL. BUG= none R=kschimpf@google.com Review URL: https://codereview.chromium.org/1180883002
parent 1a9043e7
......@@ -120,6 +120,15 @@ def main():
'-filetype=obj',
'-o=' + obj_sz,
asm_sz])
# Each separately translated Subzero object file contains its own
# definition of the __Sz_block_profile_info profiling symbol. Avoid
# linker errors (multiply defined symbol) by making all copies weak.
# (This could also be done by Subzero if it supported weak symbol
# definitions.) This approach should be OK because cross tests are
# currently the only situation where multiple translated files are
# linked into the executable, but when PNaCl supports shared nexe
# libraries, this would need to change.
shellcmd(['objcopy', '--weaken-symbol=__Sz_block_profile_info', obj_sz])
objs.append(obj_sz)
if args.crosstest_bitcode:
shellcmd(['{bin}/pnacl-llc'.format(bin=bindir),
......
......@@ -287,7 +287,6 @@ void GlobalContext::translateFunctions() {
getStrError() << "ICE translation error: " << Func->getFunctionName()
<< ": " << Func->getError() << "\n";
Item = new EmitterWorkItem(Func->getSequenceNumber());
Item->setGlobalInits(Func->getGlobalInits());
} else {
Func->getAssembler<>()->setInternal(Func->getInternal());
switch (getFlags().getOutFileType()) {
......@@ -334,6 +333,7 @@ VariableDeclaration *blockProfileInfo(const VariableDeclarationList &Globals) {
// Note: if you change this symbol, make sure to update
// runtime/szrt_profiler.c as well.
Var->setName("__Sz_block_profile_info");
Var->setSuppressMangling();
Var->setLinkage(llvm::GlobalValue::ExternalLinkage);
for (const VariableDeclaration *Global : Globals) {
if (Cfg::isProfileGlobal(*Global)) {
......
......@@ -286,9 +286,15 @@ public:
}
bool getSuppressMangling() const final {
if (ForceSuppressMangling)
return true;
return isExternal() && !hasInitializer();
}
void setSuppressMangling() {
ForceSuppressMangling = true;
}
private:
// list of initializers for the declared variable.
InitializerListType Initializers;
......@@ -296,11 +302,13 @@ private:
uint32_t Alignment;
// True if a declared (global) constant.
bool IsConstant;
// If set to true, force getSuppressMangling() to return true.
bool ForceSuppressMangling;
VariableDeclaration()
: GlobalDeclaration(VariableDeclarationKind,
llvm::GlobalValue::InternalLinkage),
Alignment(0), IsConstant(false) {}
Alignment(0), IsConstant(false), ForceSuppressMangling(false) {}
};
template <class StreamType>
......
......@@ -270,7 +270,8 @@ define void @_start(i32) {
; CHECK: ]
; CHECK: Address: 0x0
; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}}
; CHECK: Size: 48
; Size is 56 instead of 48 due to __Sz_block_profile_info .
; CHECK: Size: 56
; CHECK: Link: 0
; CHECK: Info: 0
; CHECK: AddressAlignment: 32
......
......@@ -13,6 +13,83 @@
; RUN: %p2i --assemble --disassemble --dis-flags=-t -i %s --args \
; RUN: --verbose none | FileCheck --check-prefix=SYMTAB %s
define internal i32 @main(i32 %argc, i32 %argv) {
entry:
%expanded1 = ptrtoint [4 x i8]* @PrimitiveInit to i32
call void @use(i32 %expanded1)
%expanded3 = ptrtoint [4 x i8]* @PrimitiveInitConst to i32
call void @use(i32 %expanded3)
%expanded5 = ptrtoint [4 x i8]* @PrimitiveInitStatic to i32
call void @use(i32 %expanded5)
%expanded7 = ptrtoint [4 x i8]* @PrimitiveUninit to i32
call void @use(i32 %expanded7)
%expanded9 = ptrtoint [20 x i8]* @ArrayInit to i32
call void @use(i32 %expanded9)
%expanded11 = ptrtoint [40 x i8]* @ArrayInitPartial to i32
call void @use(i32 %expanded11)
%expanded13 = ptrtoint [20 x i8]* @ArrayUninit to i32
call void @use(i32 %expanded13)
ret i32 0
}
; CHECK-LABEL: main
; CHECK: movl $PrimitiveInit,
; CHECK: movl $PrimitiveInitConst,
; CHECK: movl $PrimitiveInitStatic,
; CHECK: movl $PrimitiveUninit,
; CHECK: movl $ArrayInit,
; CHECK: movl $ArrayInitPartial,
; CHECK: movl $ArrayUninit,
; objdump does not indicate what symbol the mov/relocation applies to
; so we grep for "mov {{.*}}, OFFSET, sec", along with
; "OFFSET {{.*}} sec {{.*}} symbol" in the symbol table as a sanity check.
; NOTE: The symbol table sorting has no relation to the code's references.
; IAS-LABEL: main
; SYMTAB-LABEL: SYMBOL TABLE
; SYMTAB-DAG: 00000000 {{.*}} .data {{.*}} PrimitiveInit
; IAS: mov {{.*}},0x0 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000000 {{.*}} .rodata {{.*}} PrimitiveInitConst
; IAS: mov {{.*}},0x0 {{.*}} .rodata
; IAS: call
; SYMTAB-DAG: 00000000 {{.*}} .bss {{.*}} PrimitiveInitStatic
; IAS: mov {{.*}},0x0 {{.*}} .bss
; IAS: call
; SYMTAB-DAG: 00000004 {{.*}} .bss {{.*}} PrimitiveUninit
; IAS: mov {{.*}},0x4 {{.*}} .bss
; IAS: call
; SYMTAB-DAG: 00000004{{.*}}.data{{.*}}ArrayInit
; IAS: mov {{.*}},0x4 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000018 {{.*}} .data {{.*}} ArrayInitPartial
; IAS: mov {{.*}},0x18 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000008 {{.*}} .bss {{.*}} ArrayUninit
; IAS: mov {{.*}},0x8 {{.*}} .bss
; IAS: call
declare void @use(i32)
define internal i32 @nacl_tp_tdb_offset(i32 %__0) {
entry:
ret i32 0
}
define internal i32 @nacl_tp_tls_offset(i32 %size) {
entry:
%result = sub i32 0, %size
ret i32 %result
}
@PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
; CHECK: .type PrimitiveInit,@object
; CHECK-NEXT: .section .data,"aw",@progbits
......@@ -89,79 +166,3 @@
@__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
@__tls_template_start = internal constant [0 x i8] zeroinitializer, align 8
@__tls_template_alignment = internal constant [4 x i8] c"\01\00\00\00", align 4
define internal i32 @main(i32 %argc, i32 %argv) {
entry:
%expanded1 = ptrtoint [4 x i8]* @PrimitiveInit to i32
call void @use(i32 %expanded1)
%expanded3 = ptrtoint [4 x i8]* @PrimitiveInitConst to i32
call void @use(i32 %expanded3)
%expanded5 = ptrtoint [4 x i8]* @PrimitiveInitStatic to i32
call void @use(i32 %expanded5)
%expanded7 = ptrtoint [4 x i8]* @PrimitiveUninit to i32
call void @use(i32 %expanded7)
%expanded9 = ptrtoint [20 x i8]* @ArrayInit to i32
call void @use(i32 %expanded9)
%expanded11 = ptrtoint [40 x i8]* @ArrayInitPartial to i32
call void @use(i32 %expanded11)
%expanded13 = ptrtoint [20 x i8]* @ArrayUninit to i32
call void @use(i32 %expanded13)
ret i32 0
}
; CHECK-LABEL: main
; CHECK: movl $PrimitiveInit,
; CHECK: movl $PrimitiveInitConst,
; CHECK: movl $PrimitiveInitStatic,
; CHECK: movl $PrimitiveUninit,
; CHECK: movl $ArrayInit,
; CHECK: movl $ArrayInitPartial,
; CHECK: movl $ArrayUninit,
; objdump does not indicate what symbol the mov/relocation applies to
; so we grep for "mov {{.*}}, OFFSET, sec", along with
; "OFFSET {{.*}} sec {{.*}} symbol" in the symbol table as a sanity check.
; NOTE: The symbol table sorting has no relation to the code's references.
; IAS-LABEL: main
; SYMTAB-LABEL: SYMBOL TABLE
; SYMTAB-DAG: 00000000 {{.*}} .data {{.*}} PrimitiveInit
; IAS: mov {{.*}},0x0 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000000 {{.*}} .rodata {{.*}} PrimitiveInitConst
; IAS: mov {{.*}},0x0 {{.*}} .rodata
; IAS: call
; SYMTAB-DAG: 00000000 {{.*}} .bss {{.*}} PrimitiveInitStatic
; IAS: mov {{.*}},0x0 {{.*}} .bss
; IAS: call
; SYMTAB-DAG: 00000004 {{.*}} .bss {{.*}} PrimitiveUninit
; IAS: mov {{.*}},0x4 {{.*}} .bss
; IAS: call
; SYMTAB-DAG: 00000004{{.*}}.data{{.*}}ArrayInit
; IAS: mov {{.*}},0x4 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000018 {{.*}} .data {{.*}} ArrayInitPartial
; IAS: mov {{.*}},0x18 {{.*}} .data
; IAS: call
; SYMTAB-DAG: 00000008 {{.*}} .bss {{.*}} ArrayUninit
; IAS: mov {{.*}},0x8 {{.*}} .bss
; IAS: call
declare void @use(i32)
define internal i32 @nacl_tp_tdb_offset(i32 %__0) {
entry:
ret i32 0
}
define internal i32 @nacl_tp_tls_offset(i32 %size) {
entry:
%result = sub i32 0, %size
ret i32 %result
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment