This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Windows: fix test uses wrong pragma to declare crt initializer.

Authored by mcgov on Mar 12 2019, 2:21 PM.



previous test used #pragma data_seg(".CRT.....") to allocate a user defines initializer in the .crt$ segment. A small bug, the correct way to declare this is with init_seg rather than data_seg.

Diff Detail

Event Timeline

mcgov created this revision.Mar 12 2019, 2:21 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 12 2019, 2:21 PM
Herald added subscribers: Restricted Project, llvm-commits, jdoerfert and 2 others. · View Herald Transcript
mcgov added a comment.Mar 12 2019, 2:22 PM
This comment was removed by mcgov.

No objection from the mingw perspective. Sanitizers on mingw are only supported by clang+lld, not by gcc/ld.bfd, and then it's built by clang in mingw mode with -fms-extensions, so most msvc specific extensions are available. Additionally, I haven't even yet a full setup for running compiler-rt/libcxx runtime tests, so I'm not sure if there are other things that need to be fixed wrt mingw in the tests.

rnk added a comment.Mar 12 2019, 3:03 PM

I don't think this change is correct, the test is creating a global variable, run_on_startup, and allocating it into .CRT$XIB. There are no initializers involved, which is what #pragma init_seg controls. We'd have to restructure the test like so for that to make sense:

#pragma init_seg(".crt$XIB")
struct AutoIniti { AutoInit() { call_me_maybe(); } } run_on_startup;

This test is essentially rolling its own initializer, so data_seg is the right pragma. Another way to do this would be to use #pragma section / __declspec(allocate).

When I apply your patch locally and compile the test with clang-cl, I see that no .CRT$XIB section is present in the object file.

mcgov planned changes to this revision.Mar 12 2019, 3:07 PM

Oh wow, good catch. Thank you Reid.

mcgov abandoned this revision.Mar 12 2019, 3:48 PM

Yep! 100% I made a mistake, the test should remain the same. I'm going to abandon this revision. Thank you for your quick review!