New global constructor warnings in runtime GlobalObjects.cpp


(Joe Groff) #1

After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                      ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                           ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                    ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?

-Joe


(John McCall) #2

Can you tell from the object file whether a global constructor is needed?

John.

···

On May 2, 2017, at 12:02 PM, Joe Groff via swift-dev <swift-dev@swift.org> wrote:
After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                     ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                          ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                   ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?


(Joe Groff) #3

There is a global constructor, but it appears to be for another definition in the same file (and which legitimately needs the global ctor).

-Joe

···

On May 2, 2017, at 9:36 AM, John McCall <rjmccall@apple.com> wrote:

On May 2, 2017, at 12:02 PM, Joe Groff via swift-dev <swift-dev@swift.org> wrote:
After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                    ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                         ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                  ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?

Can you tell from the object file whether a global constructor is needed?


(John McCall) #4

Okay. If -Wglobal-constructors has regressed, that's a pretty serious bug that we should fix.

John.

···

On May 2, 2017, at 12:57 PM, Joe Groff <jgroff@apple.com> wrote:

On May 2, 2017, at 9:36 AM, John McCall <rjmccall@apple.com> wrote:

On May 2, 2017, at 12:02 PM, Joe Groff via swift-dev <swift-dev@swift.org> wrote:
After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                   ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                        ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                 ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?

Can you tell from the object file whether a global constructor is needed?

There is a global constructor, but it appears to be for another definition in the same file (and which legitimately needs the global ctor).


(Joe Groff) #5

OK, I'll see if I can reproduce it and submit a Clang bug.

-Joe

···

On May 2, 2017, at 10:07 AM, John McCall <rjmccall@apple.com> wrote:

On May 2, 2017, at 12:57 PM, Joe Groff <jgroff@apple.com> wrote:

On May 2, 2017, at 9:36 AM, John McCall <rjmccall@apple.com> wrote:

On May 2, 2017, at 12:02 PM, Joe Groff via swift-dev <swift-dev@swift.org> wrote:
After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                  ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                       ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?

Can you tell from the object file whether a global constructor is needed?

There is a global constructor, but it appears to be for another definition in the same file (and which legitimately needs the global ctor).

Okay. If -Wglobal-constructors has regressed, that's a pretty serious bug that we should fix.


(John McCall) #6

Where "we" == "they", of course, sorry. :slight_smile:

John.

···

On May 2, 2017, at 1:07 PM, John McCall via swift-dev <swift-dev@swift.org> wrote:

On May 2, 2017, at 12:57 PM, Joe Groff <jgroff@apple.com> wrote:

On May 2, 2017, at 9:36 AM, John McCall <rjmccall@apple.com> wrote:

On May 2, 2017, at 12:02 PM, Joe Groff via swift-dev <swift-dev@swift.org> wrote:
After updating clang recently, I'm seeing these warnings:

/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:40:39: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
                                  ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:55:44: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
                                       ^ ~
/Users/jgroff/src/s/swift/stdlib/public/stubs/GlobalObjects.cpp:83:37: warning: declaration requires a global constructor [-Wglobal-constructors]
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
                                ^ ~

Looking at the definitions of those objects, it isn't clear to me why they would require global constructors. The types are POD, and their initializers only contain pointers to other globals, which ought to be resolvable by the linker. I also didn't see any recent change to the runtime that seems like it would trigger a change here. Is this a clang bug?

Can you tell from the object file whether a global constructor is needed?

There is a global constructor, but it appears to be for another definition in the same file (and which legitimately needs the global ctor).

Okay. If -Wglobal-constructors has regressed, that's a pretty serious bug that we should fix.