From 031c4577bdc5b56225606fb02b1028145767ffd7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 28 Jan 2017 17:00:14 -0800 Subject: [PATCH] Fix the size of the NDK .note.android.ident ELF note. Also allow the variables to be set directly by -D rather than using sed. Bug: http://b/34779141 Test: builds Change-Id: Ie81b2f0194d11bdfeffc2ded29ae456420a9f20d --- ndk/platforms/common/src/crtbrand.c | 30 +++++------------------------ 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/ndk/platforms/common/src/crtbrand.c b/ndk/platforms/common/src/crtbrand.c index 418c1947d..2065e3c83 100644 --- a/ndk/platforms/common/src/crtbrand.c +++ b/ndk/platforms/common/src/crtbrand.c @@ -23,6 +23,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// TODO: this file should just be a .S file like bionic's crtbrand. + /* The following trick defines int32_t w/o including We want "int" to be 4-byte. But just in case it isn't, the following line turns into "typedef int int32_t[0]" and later fails with error messages @@ -36,42 +38,20 @@ typedef int int32_t[sizeof(int) == 4]; #define ABI_SECTION ".note.android.ident" #define ABI_NOTETYPE 1 #define ABI_ANDROID_API PLATFORM_SDK_VERSION -#define ABI_NDK_VERSION "%NDK_VERSION%" -#define ABI_NDK_BUILD_NUMBER "%NDK_BUILD_NUMBER%" #define NDK_RESERVED_SIZE 64 -#define L 9999 - -/* - * Special ".note" entry to tag an Android binary and specify the ABI version. - * - * For all arches except sparc, gcc emits the section directive for the - * following struct with a PROGBITS type. However, the section should be - * of NOTE type, according to the Generic SysV ABI spec. - * - * Unfortunately, there is no clean way to tell gcc to use another section type, - * so this C file (or the C file that includes it) must be compiled in multiple - * steps: - * - * - Compile the .c file to a .s file. - * - Edit the .s file to change the 'progbits' type to 'note', for the section - * directive that defines the .note.ABI-tag section. - * - Compile the .s file to an object file. - * - * These steps are done in the invididual Makefiles for each applicable arch. - */ static const struct { int32_t namesz; int32_t descsz; int32_t type; - char name[sizeof ABI_VENDOR]; + char name[sizeof(ABI_VENDOR)]; int32_t android_api; char ndk_version[NDK_RESERVED_SIZE]; char ndk_build_number[NDK_RESERVED_SIZE]; } abitag __attribute__ ((section (ABI_SECTION), aligned(4), used)) = { - sizeof ABI_VENDOR, - sizeof(int32_t), + sizeof(ABI_VENDOR), + sizeof(int32_t) + NDK_RESERVED_SIZE + NDK_RESERVED_SIZE, ABI_NOTETYPE, ABI_VENDOR, ABI_ANDROID_API,