在 Chromuim (Android) 中为 elf_utils 使用 Clang 编译嵌套函数

To compile nested functions with Clang for elf_utils in Chromuim (Android)

我正在尝试为 Android 构建 Chromium 代码并卡在编译 elfutilsninja -C opt/Full chrome_public_apk 命令,我将此作为异常

[30/21982] CC clang_x64/obj/third_party/elfutils/libelf/elf32_updatefile.o

FAILED: clang_x64/obj/third_party/elfutils/libelf/elf32_updatefile.o

../../third_party/llvm-build/Release+Asserts/bin/clang -MMD -MF clang_x64/obj/third_party/elfutils/libelf/elf32_updatefile.o.d -D_GNU_SOURCE -DHAVE_CONFIG_H -DV8_DEPRECATION_WARNINGS -DENABLE_MDNS=1 -DENABLE_NOTIFICATIONS -DENABLE_PEPPER_CDMS -DENABLE_PLUGINS=1 -DENABLE_PDF=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DUSE_UDEV -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_CLIPBOARD_AURAX11=1 -DUSE_DEFAULT_RENDER_THEME=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DENABLE_WEBRTC=1 -DENABLE_EXTENSIONS=1 -DENABLE_TASK_MANAGER=1 -DENABLE_THEMES=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_SERVICE_DISCOVERY=1 -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -DENABLE_MEDIA_ROUTER=1 -DFIELDTRIAL_TESTING_ENABLED -DCR_CLANG_REVISION=274369-1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_GLIBCXX_DEBUG=1 -I../../third_party/elfutils -I../../third_party/elfutils/src/lib -I../.. -Iclang_x64/gen -I../../third_party/elfutils/src/libelf -std=gnu99 -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -pipe -B../../third_party/binutils/Linux_x64/Release/bin -fcolor-diagnostics -fdebug-prefix-map=/home/vcareall/Yogesh/CompanyCode/chromium/src=. -pthread -m64 -march=x86-64 -O0 -g2 -gsplit-dwarf --sysroot=../../build/linux/debian_wheezy_amd64-sysroot -fvisibility=hidden -Xclang -load -Xclang ../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion -Xclang -plugin-arg-find-bad-constructs -Xclang check-implicit-copy-ctors -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -Werror -Wall -Wno-unused-variable -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-deprecated-register -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wno-undefined-var-template -Wno-nonportable-include-path -c ../../third_party/elfutils/src/libelf/elf32_updatefile.c -o clang_x64/obj/third_party/elfutils/libelf/elf32_updatefile.o

../../third_party/elfutils/src/libelf/elf32_updatefile.c:297:4: error: function definition is not allowed here

{

^

../../third_party/elfutils/src/libelf/elf32_updatefile.c:331:7: error: implicit declaration of function 'fill_mmap' is invalid in C99 [-Werror,-Wimplicit-function-declaration] fill_mmap (dl->data.d.d_off);

^

2 errors generated.

[35/21982] CXX clang_x64/obj/third_party/android_protobuf/android_protoc/javamicro_file.o ninja: build stopped: subcommand failed.

我不熟悉 ninja 构建系统的工作和配置。 但我已经读到 Clang 它不会编译嵌套函数,而 G++ 可以做到这一点。 但我不知道如何为 运行 G++ 设置 Ninja 来编译所有嵌套函数 C 代码。

有人对此有什么建议吗?

您不能使用 clang 编译带有嵌套函数的代码。来自 clang 文档(https://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet):

clang does not support nested functions; this is a complex feature which is infrequently used, so it is unlikely to be implemented anytime soon.

要将 g++ 与 ninja 一起使用,您可以更改环境变量 CC 和 CXX,如下所示(unix-based os 隐含):

$ export CC=/path/to/gcc
$ export CXX=/path/to/g++

或者如果 ninja 不使用 those 变量,则在 .ninja 文件中将 clang 更改为 g++