Commit 10bcc4d1 authored by Peter Collingbourne's avatar Peter Collingbourne Committed by Commit Bot

Reland "build: Pass -fcomplete-member-pointers when building with clang."

This is a reland of 4a2a5c4a
with an additional check for use_xcode_clang.

Original change's description:
> build: Pass -fcomplete-member-pointers when building with clang.
>
> This prevents member pointers of incomplete base type from being used in
> cases where they might cause problems under the Microsoft ABI.
>
> Specifically, the Microsoft ABI has different kinds of member pointers with
> different sizes, and the choice of member pointer representation depends on
> the inheritance hierarchy of the member pointer's base type. C++ allows a
> member pointer's base type to be incomplete, so if it is incomplete at the
> point where a variable of that member pointer type is declared, that forces
> the compiler to pick the most general (i.e. largest) one. That can lead to
> ODR violations since the most general representation wouldn't necessarily
> be the one that would be chosen if the base type happened to be complete at
> the point where the variable was declared. It can also be less size efficient
> because the compiler will generally be able to choose a smaller representation
> than the most general one if it were complete at the point where it is needed.
>
> This flag also enables additional semantic analysis that we'll need in order
> to correctly implement -fsanitize=cfi for member function pointer calls. This
> is because the inheritance hierarchy of the base type must be available in
> order to make the CFI checks as precise as possible.
>
> Note that the flag is a -f flag rather than a -W flag. This is because
> requiring member pointer base types to be complete is technically a
> non-conforming language extension, as it may, for example, cause templates
> to be instantiated which would otherwise not be, which may be observable
> after code generation in conforming programs that were crafted to observe
> it. However, the effects of this language extension should not be observable
> in most ordinary programs.
>
> Bug: 847724
> Change-Id: I8d823fd4a6f21dfcadba55eefc0a69ef2e0c3479
> Reviewed-on: https://chromium-review.googlesource.com/1098217
> Commit-Queue: Peter Collingbourne <pcc@chromium.org>
> Reviewed-by: Nico Weber <thakis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#567086}

Bug: 847724
Change-Id: I1b97980691914492945d170931d33438c68e8d0b
Reviewed-on: https://chromium-review.googlesource.com/1101477Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567505}
parent 68bd2e31
......@@ -672,6 +672,13 @@ config("compiler") {
ldflags += [ "-Wl,--no-rosegment" ]
}
# This flag enforces that member pointer base types are complete. It helps
# prevent us from running into problems in the Microsoft C++ ABI (see
# https://crbug.com/847724).
if (is_clang && !is_nacl && target_os != "chromeos" && !use_xcode_clang) {
cflags += [ "-fcomplete-member-pointers" ]
}
# Pass the same C/C++ flags to the objective C/C++ compiler.
cflags_objc += cflags_c
cflags_objcc += cflags_cc
......
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