New issue
Advanced search Search tips

Issue 631489 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Jul 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 3
Type: Bug



Sign in to add a comment

Android NDK __func__ definition is inconsistent with glibc and C++99.

Project Member Reported by primiano@chromium.org, Jul 26 2016

Issue description

Copying from internal bug b/30353757

Got fixed in bionic upstream in https://android-review.googlesource.com/#/c/250323/

TL;DR
arch-arm/usr/include/sys/cdefs.h re-defines __func__ = __PRETTY_FUNCTION__

This causes the following problems:
 - Breaks C++99 section 6.4.2.2
 - Is inconsistent with glibc headers, which don't define (at least on debian wheezy) __func__ at all, and maintain the original gcc behavior where __func__ == __FUNCTION__ (!=__PRETTY_FUNCTION__)
 - Is inconsistent with GCC doc (https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html) that says
   "_FUNCTION__ is another name for __func__, provided for backward compatibility with old versions of GCC."
   (For the lovers of the genre who still believe and rely on GCC docs consistency)

Repro steps:
$ cat > /tmp/repro.cc <<EOF
void getFunctPre(const char** a, const char** b) {
 *a = __func__;
 *b = __FUNCTION__;
}

#include <stdio.h>

void getFunctPost(const char** a, const char** b) {
 *a = __func__;
 *b = __FUNCTION__;
}

int main() {
 const char* a, *b;

 printf("\nPRE stdio include\n");
 getFunctPre(&a, &b);
 printf("__func__ = %s\n__FUNCTION__ = %s\n", a, b);

 printf("\nPOST stdio include\n");
 getFunctPost(&a, &b);
 printf("__func__ = %s\n__FUNCTION__ = %s\n", a, b);

 return 0;
}
EOF


$ ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
-pie --sysroot=ndk/platforms/android-16/arch-arm -march=armv7-a -mthumb \
-o /tmp/test /tmp/test.cc -std=c++11

$ adb push /tmp/test /data/local/tmp/test && adb shell /data/local/tmp/test

PRE stdio include
__func__ = getFunctPre
__FUNCTION__ = getFunctPre

POST stdio include
__func__ = void getFunctPost(const char**, const char**) !!!!!!!!!!!!!!!!!!!!!!!!!!!!
__FUNCTION__ = getFunctPost

The culprit seems in ndk/platforms/android-16/arch-arm/usr/include/sys/cdefs.h
/*
 * C99 defines __func__ predefined identifier, which was made available
 * in GCC 2.95.
 */
#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
#if __GNUC_PREREQ(2, 6)
#define __func__        __PRETTY_FUNCTION__
#elif __GNUC_PREREQ(2, 4)
#define __func__        __FUNCTION__
#else
#define __func__        ""
#endif
#endif /* !(__STDC_VERSION__ >= 199901L) */

I think this sections should just be ripped out. __func__ should be a builtin in modern compilers.
 
Project Member

Comment 1 by bugdroid1@chromium.org, Jul 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/93a742ec131721a325f582f3d61bf0b75bee134a

commit 93a742ec131721a325f582f3d61bf0b75bee134a
Author: primiano <primiano@chromium.org>
Date: Tue Jul 26 20:12:01 2016

Roll src/third_party/android_tools/ e4d61eb8f..af1c5a4cd (1 commit).

https://chromium.googlesource.com/android_tools.git/+log/e4d61eb8f463..af1c5a4cd632

$ git log e4d61eb8f..af1c5a4cd --date=short --no-merges --format='%ad %ae %s'
2016-07-26 primiano NDK: cherry-pick fix to make __func__ C99 compliant.

BUG= 631489 

Review-Url: https://codereview.chromium.org/2180223004
Cr-Commit-Position: refs/heads/master@{#407897}

[modify] https://crrev.com/93a742ec131721a325f582f3d61bf0b75bee134a/DEPS

Status: Fixed (was: Started)

Sign in to add a comment