[llvm-bugs] [Bug 46500] New: In Windows global_dtors calls before main or fails program after main

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 29 06:09:01 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46500

            Bug ID: 46500
           Summary: In Windows global_dtors calls before main or fails
                    program after main
           Product: libraries
           Version: 9.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: tarasber at yandex.ru
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

Created attachment 23654
  --> https://bugs.llvm.org/attachment.cgi?id=23654&action=edit
file to compile

Here is .ll code:

;---------------------------------------------------------------------
; ModuleID = 't.ll'
source_filename = "t.ll"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.24.28316"

%type.3 = type { i32 }

@string.2 = private unnamed_addr constant { i32, [2 x i8] } { i32 2, [2 x i8]
c"A\00" }
@global.95 = private local_unnamed_addr global %type.3 zeroinitializer
@string.4 = private unnamed_addr constant { i32, [5 x i8] } { i32 5, [5 x i8]
c"main\00" }
@string.5 = private unnamed_addr constant { i32, [5 x i8] } { i32 5, [5 x i8]
c"~A()\00" }
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 0, void ()* @global.ctors, i8* null }]
@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 65535, void ()* @global.dtors, i8* null }] ;
<---------------------------- here I changed dtor priority

@t.a.0 = alias %type.3, %type.3* @global.95

; Function Attrs: nofree nounwind
define internal void @global.ctors() #0 {
  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ({ i32, [2 x i8]
}, { i32, [2 x i8] }* @string.2, i64 0, i32 1, i64 0)) #1
  store i32 0, i32* getelementptr inbounds (%type.3, %type.3* @global.95, i64
0, i32 0), align 8
  ret void
}

; Function Attrs: nofree nounwind
define internal void @global.dtors() #0 {
  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ({ i32, [5 x i8]
}, { i32, [5 x i8] }* @string.5, i64 0, i32 1, i64 0)) #1
  ret void
}

; Function Attrs: nofree nounwind
declare void @printf(i8* nocapture readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
define i32 @main() local_unnamed_addr #0 {
label0:
  tail call void (i8*, ...) @printf(i8* getelementptr inbounds ({ i32, [5 x i8]
}, { i32, [5 x i8] }* @string.4, i64 0, i32 1, i64 0))
  ret i32 0
}

attributes #0 = { nofree nounwind }
attributes #1 = { nounwind }
;-------------------------------------------------------------------------------
then I try to compile&run it:

clang t.ll
a.exe

I tried to change priority of global_dtor to differentvalues.
When I make in 0,1,...65534 global_dtor calls BEFORE main.
When I make it 65535, program fails after main.

In Linux all values of priority of global_dtor generate correct program.
So now I have the only way to generate correct global_dtors - generate
platform-specifix quirks line "atexit" etc. But it is not good, I hove llvm
will fix this bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200629/9f210a6c/attachment-0001.html>


More information about the llvm-bugs mailing list