[llvm] r233229 - llvm-link: Verify input modules

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Mar 25 16:22:11 PDT 2015


Author: dexonsmith
Date: Wed Mar 25 18:22:10 2015
New Revision: 233229

URL: http://llvm.org/viewvc/llvm-project?rev=233229&view=rev
Log:
llvm-link: Verify input modules

Otherwise, broken input modules can cause assertions.  I've updated two
of the testcases that started failing (modules that had `Require` flags
but didn't meet their own requirements), but Rafael and I decided that
test/Linker/2011-08-22-ResolveAlias.ll should just be deleted outright
-- it's a leftover of the way llvm-gcc used to implement weakref.

Added:
    llvm/trunk/test/Linker/broken.ll
Removed:
    llvm/trunk/test/Linker/2011-08-22-ResolveAlias.ll
    llvm/trunk/test/Linker/2011-08-22-ResolveAlias2.ll
Modified:
    llvm/trunk/test/Linker/module-flags-3-b.ll
    llvm/trunk/test/Linker/module-flags-4-b.ll
    llvm/trunk/tools/llvm-link/llvm-link.cpp

Removed: llvm/trunk/test/Linker/2011-08-22-ResolveAlias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/2011-08-22-ResolveAlias.ll?rev=233228&view=auto
==============================================================================
--- llvm/trunk/test/Linker/2011-08-22-ResolveAlias.ll (original)
+++ llvm/trunk/test/Linker/2011-08-22-ResolveAlias.ll (removed)
@@ -1,89 +0,0 @@
-; PR10663
-; RUN: llvm-link %s %p/2011-08-22-ResolveAlias2.ll
-
-%union.pthread_attr_t = type { [56 x i8] }
-%union.pthread_mutex_t = type { [40 x i8] }
-%struct.timespec = type { i64, i64 }
-%union.pthread_mutexattr_t = type { [4 x i8] }
-%union.pthread_cond_t = type { [48 x i8] }
-
- at _ZL20__gthrw_pthread_oncePiPFvvE = weak alias i32 (i32*, void ()*)* @pthread_once
- at _ZL27__gthrw_pthread_getspecificj = weak alias i8* (i32)* @pthread_getspecific
- at _ZL27__gthrw_pthread_setspecificjPKv = weak alias i32 (i32, i8*)* @pthread_setspecific
- at _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_ = weak alias i32 (i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)* @pthread_create
- at _ZL20__gthrw_pthread_joinmPPv = weak alias i32 (i64, i8**)* @pthread_join
- at _ZL21__gthrw_pthread_equalmm = weak alias i32 (i64, i64)* @pthread_equal
- at _ZL20__gthrw_pthread_selfv = weak alias i64 ()* @pthread_self
- at _ZL22__gthrw_pthread_detachm = weak alias i32 (i64)* @pthread_detach
- at _ZL22__gthrw_pthread_cancelm = weak alias i32 (i64)* @pthread_cancel
- at _ZL19__gthrw_sched_yieldv = weak alias i32 ()* @sched_yield
- at _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_lock
- at _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_trylock
- at _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec = weak alias i32 (%union.pthread_mutex_t*, %struct.timespec*)* @pthread_mutex_timedlock
- at _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_unlock
- at _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutex_t*, %union.pthread_mutexattr_t*)* @pthread_mutex_init
- at _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_destroy
- at _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_broadcast
- at _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_signal
- at _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t = weak alias i32 (%union.pthread_cond_t*, %union.pthread_mutex_t*)* @pthread_cond_wait
- at _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec = weak alias i32 (%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*)* @pthread_cond_timedwait
- at _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_destroy
- at _ZL26__gthrw_pthread_key_createPjPFvPvE = weak alias i32 (i32*, void (i8*)*)* @pthread_key_create
- at _ZL26__gthrw_pthread_key_deletej = weak alias i32 (i32)* @pthread_key_delete
- at _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutexattr_t*)* @pthread_mutexattr_init
- at _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = weak alias i32 (%union.pthread_mutexattr_t*, i32)* @pthread_mutexattr_settype
- at _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutexattr_t*)* @pthread_mutexattr_destroy
-
-declare extern_weak i32 @pthread_once(i32*, void ()*)
-
-declare extern_weak i8* @pthread_getspecific(i32)
-
-declare extern_weak i32 @pthread_setspecific(i32, i8*)
-
-declare extern_weak i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
-
-declare extern_weak i32 @pthread_join(i64, i8**)
-
-declare extern_weak i32 @pthread_equal(i64, i64)
-
-declare extern_weak i64 @pthread_self()
-
-declare extern_weak i32 @pthread_detach(i64)
-
-declare extern_weak i32 @pthread_cancel(i64)
-
-declare extern_weak i32 @sched_yield()
-
-declare extern_weak i32 @pthread_mutex_lock(%union.pthread_mutex_t*)
-
-declare extern_weak i32 @pthread_mutex_trylock(%union.pthread_mutex_t*)
-
-declare extern_weak i32 @pthread_mutex_timedlock(%union.pthread_mutex_t*, %struct.timespec*)
-
-declare extern_weak i32 @pthread_mutex_unlock(%union.pthread_mutex_t*)
-
-declare extern_weak i32 @pthread_mutex_init(%union.pthread_mutex_t*, %union.pthread_mutexattr_t*)
-
-declare extern_weak i32 @pthread_mutex_destroy(%union.pthread_mutex_t*)
-
-declare extern_weak i32 @pthread_cond_broadcast(%union.pthread_cond_t*)
-
-declare extern_weak i32 @pthread_cond_signal(%union.pthread_cond_t*)
-
-declare extern_weak i32 @pthread_cond_wait(%union.pthread_cond_t*, %union.pthread_mutex_t*)
-
-declare extern_weak i32 @pthread_cond_timedwait(%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*)
-
-declare extern_weak i32 @pthread_cond_destroy(%union.pthread_cond_t*)
-
-declare extern_weak i32 @pthread_key_create(i32*, void (i8*)*)
-
-declare extern_weak i32 @pthread_key_delete(i32)
-
-declare extern_weak i32 @pthread_mutexattr_init(%union.pthread_mutexattr_t*)
-
-declare extern_weak i32 @pthread_mutexattr_settype(%union.pthread_mutexattr_t*, i32)
-
-declare extern_weak i32 @pthread_mutexattr_destroy(%union.pthread_mutexattr_t*)
-
-declare void @_GLOBAL__sub_I__ZN10BitBoard64coEv() nounwind uwtable

Removed: llvm/trunk/test/Linker/2011-08-22-ResolveAlias2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/2011-08-22-ResolveAlias2.ll?rev=233228&view=auto
==============================================================================
--- llvm/trunk/test/Linker/2011-08-22-ResolveAlias2.ll (original)
+++ llvm/trunk/test/Linker/2011-08-22-ResolveAlias2.ll (removed)
@@ -1,146 +0,0 @@
-; This file is used by 2011-08-22-ResolveAlias.ll
-; RUN: true
-
-%struct.HexxagonBoard = type { %struct.BitBoard64, %struct.BitBoard64 }
-%struct.BitBoard64 = type { i32, i32 }
-%union.pthread_attr_t = type { [56 x i8] }
-%union.pthread_mutex_t = type { [40 x i8] }
-%struct.timespec = type { i64, i64 }
-%union.pthread_mutexattr_t = type { [4 x i8] }
-%union.pthread_cond_t = type { [48 x i8] }
-
- at _ZN13HexxagonBoardC1ERKS_ = alias void (%struct.HexxagonBoard*, %struct.HexxagonBoard*)* @_ZN13HexxagonBoardC2ERKS_
- at _ZL20__gthrw_pthread_oncePiPFvvE = weak alias i32 (i32*, void ()*)* @pthread_once
- at _ZL27__gthrw_pthread_getspecificj = weak alias i8* (i32)* @pthread_getspecific
- at _ZL27__gthrw_pthread_setspecificjPKv = weak alias i32 (i32, i8*)* @pthread_setspecific
- at _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_ = weak alias i32 (i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)* @pthread_create
- at _ZL20__gthrw_pthread_joinmPPv = weak alias i32 (i64, i8**)* @pthread_join
- at _ZL21__gthrw_pthread_equalmm = weak alias i32 (i64, i64)* @pthread_equal
- at _ZL20__gthrw_pthread_selfv = weak alias i64 ()* @pthread_self
- at _ZL22__gthrw_pthread_detachm = weak alias i32 (i64)* @pthread_detach
- at _ZL22__gthrw_pthread_cancelm = weak alias i32 (i64)* @pthread_cancel
- at _ZL19__gthrw_sched_yieldv = weak alias i32 ()* @sched_yield
- at _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_lock
- at _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_trylock
- at _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec = weak alias i32 (%union.pthread_mutex_t*, %struct.timespec*)* @pthread_mutex_timedlock
- at _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_unlock
- at _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutex_t*, %union.pthread_mutexattr_t*)* @pthread_mutex_init
- at _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t = weak alias i32 (%union.pthread_mutex_t*)* @pthread_mutex_destroy
- at _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_broadcast
- at _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_signal
- at _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t = weak alias i32 (%union.pthread_cond_t*, %union.pthread_mutex_t*)* @pthread_cond_wait
- at _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec = weak alias i32 (%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*)* @pthread_cond_timedwait
- at _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t = weak alias i32 (%union.pthread_cond_t*)* @pthread_cond_destroy
- at _ZL26__gthrw_pthread_key_createPjPFvPvE = weak alias i32 (i32*, void (i8*)*)* @pthread_key_create
- at _ZL26__gthrw_pthread_key_deletej = weak alias i32 (i32)* @pthread_key_delete
- at _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutexattr_t*)* @pthread_mutexattr_init
- at _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = weak alias i32 (%union.pthread_mutexattr_t*, i32)* @pthread_mutexattr_settype
- at _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = weak alias i32 (%union.pthread_mutexattr_t*)* @pthread_mutexattr_destroy
-
-define void @_ZN13HexxagonBoardC2ERKS_(%struct.HexxagonBoard*, %struct.HexxagonBoard*) uwtable align 2 {
-  ret void
-}
-
-define weak i32 @pthread_once(i32*, void ()*) {
-  ret i32 0
-}
-
-define weak i8* @pthread_getspecific(i32) {
-  ret i8* null
-}
-
-define weak i32 @pthread_setspecific(i32, i8*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_join(i64, i8**) {
-  ret i32 0
-}
-
-define weak i32 @pthread_equal(i64, i64) {
-  ret i32 0
-}
-
-define weak i64 @pthread_self() {
-  ret i64 0
-}
-
-define weak i32 @pthread_detach(i64) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cancel(i64) {
-  ret i32 0
-}
-
-define weak i32 @sched_yield() {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_lock(%union.pthread_mutex_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_trylock(%union.pthread_mutex_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_timedlock(%union.pthread_mutex_t*, %struct.timespec*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_unlock(%union.pthread_mutex_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_init(%union.pthread_mutex_t*, %union.pthread_mutexattr_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutex_destroy(%union.pthread_mutex_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cond_broadcast(%union.pthread_cond_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cond_signal(%union.pthread_cond_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cond_wait(%union.pthread_cond_t*, %union.pthread_mutex_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cond_timedwait(%union.pthread_cond_t*, %union.pthread_mutex_t*, %struct.timespec*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_cond_destroy(%union.pthread_cond_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_key_create(i32*, void (i8*)*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_key_delete(i32) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutexattr_init(%union.pthread_mutexattr_t*) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutexattr_settype(%union.pthread_mutexattr_t*, i32) {
-  ret i32 0
-}
-
-define weak i32 @pthread_mutexattr_destroy(%union.pthread_mutexattr_t*) {
-  ret i32 0
-}

Added: llvm/trunk/test/Linker/broken.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/broken.ll?rev=233229&view=auto
==============================================================================
--- llvm/trunk/test/Linker/broken.ll (added)
+++ llvm/trunk/test/Linker/broken.ll Wed Mar 25 18:22:10 2015
@@ -0,0 +1,8 @@
+; RUN: not llvm-link -o /dev/null %s 2>&1 | FileCheck %s
+
+; CHECK: input module '{{.*}}broken.ll' is broken
+define i32 @foo(i32 %v) {
+  %first = add i32 %v, %second
+  %second = add i32 %v, 3
+  ret i32 %first
+}

Modified: llvm/trunk/test/Linker/module-flags-3-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/module-flags-3-b.ll?rev=233229&r1=233228&r2=233229&view=diff
==============================================================================
--- llvm/trunk/test/Linker/module-flags-3-b.ll (original)
+++ llvm/trunk/test/Linker/module-flags-3-b.ll Wed Mar 25 18:22:10 2015
@@ -2,5 +2,6 @@
 ; RUN: true
 
 !0 = !{i32 3, !"foo", !{!"bar", i32 42}}
+!1 = !{i32 1, !"bar", i32 42}
 
-!llvm.module.flags = !{ !0 }
+!llvm.module.flags = !{ !0, !1 }

Modified: llvm/trunk/test/Linker/module-flags-4-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/module-flags-4-b.ll?rev=233229&r1=233228&r2=233229&view=diff
==============================================================================
--- llvm/trunk/test/Linker/module-flags-4-b.ll (original)
+++ llvm/trunk/test/Linker/module-flags-4-b.ll Wed Mar 25 18:22:10 2015
@@ -2,5 +2,6 @@
 ; RUN: true
 
 !0 = !{i32 3, !"foo", !{!"bar", i32 42}}
+!1 = !{i32 2, !"bar", i32 42}
 
-!llvm.module.flags = !{ !0 }
+!llvm.module.flags = !{ !0, !1 }

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=233229&r1=233228&r2=233229&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Wed Mar 25 18:22:10 2015
@@ -112,6 +112,12 @@ int main(int argc, char **argv) {
       return 1;
     }
 
+    if (verifyModule(*M)) {
+      errs() << argv[0] << ": input module '" << InputFilenames[i]
+             << "' is broken!\n";
+      return 1;
+    }
+
     if (Verbose) errs() << "Linking in '" << InputFilenames[i] << "'\n";
 
     if (L.linkInModule(M.get()))





More information about the llvm-commits mailing list