Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile AOSP with CodeQL #47

Open
to-the-batmobile opened this issue Oct 18, 2020 · 10 comments
Open

compile AOSP with CodeQL #47

to-the-batmobile opened this issue Oct 18, 2020 · 10 comments
Assignees
Labels
CLI

Comments

@to-the-batmobile
Copy link

@to-the-batmobile to-the-batmobile commented Oct 18, 2020

Hi
I'm trying to run CodeQL on AOSP with this command:
codeql database create new-database --language=java --command='make services'
but i'm getting this error while building:
[build] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: out/soong/.intermediates/external/libcxx/libc++_static/darwin_x86_64_static/libc++_static.a(cxa_unexpected.o) has no symbols [build] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: out/soong/.intermediates/external/libcxx/libc++_static/darwin_x86_64_static/libc++_static.a(typeinfo.o) has no symbols [build] 17:09:55 Disallowed PATH tool "otool" used: []string{"otool", "-l", "/Volumes/v0/AOSP/new-database/working/copy-root/000001F7/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld.semmle.00013D12"} [build] 17:09:55 See https://android.googlesource.com/platform/build/+/master/Changes.md#PATH_Tools for more information. [build] 17:09:55 Process tree: [build] 17:09:55 → working/copy-root/000001F7/Volumes/v0/AOSP/out/soong_ui /Volumes/v0/AOSP/out/soong_ui -j1 --make-mode [build] 17:09:55 → prebuilts/build-tools/darwin-x86/bin/ninja -d keepdepfile --frontend_file out/.ninja_fifo services -j 1 -f out/combined-aosp_sargo.ninja -w dupbuild=err -w missingdepfile=err [build] 17:09:55 → prebuilts/clang/host/darwin-x86/clang-r353983c/bin/clang++.real @out/soong/.intermediates/external/libcxx/libc++/darwin_x86_64_shared/libc++.dylib.rsp -force_load out/soong/.intermediates/external/libcxx/libc++_static/darwin_x86_64_static/libc++_static.a -o out/soong/.intermediates/external/libcxx/libc++/darwin_x86_64_shared/libc++.dylib -dynamiclib -single_module -install_name @rpath/libc++.dylib -target x86_64-apple-darwin -B/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.8 -m64 -ldl -lpthread -lm -nodefaultlibs -Wl,-undefined,dynamic_lookup -Wl,-rpath,@loader_path/../lib64 -Wl,-rpath,@loader_path/lib64 -nodefaultlibs -lc -lSystem -Wl,-unexported_symbols_list,external/libcxx/lib/libc++unexp.exp -Wl,-force_symbols_not_weak_list,external/libcxx/lib/notweak.exp -Wl,-force_symbols_weak_list,external/libcxx/lib/weak.exp [build] 17:09:55 → /usr/bin/python /Users/user/codeql-home/codeql/tools/osx64/relocator.py /Users/user/codeql-home/codeql/tools/osx64/unsign /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld /Volumes/v0/AOSP/new-database/working/copy-root/000001F7/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld.semmle.00013D12 /Volumes/v0/AOSP/new-database/working/copy-root/000001F7/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld [build] 17:09:55 → otool -l /Volumes/v0/AOSP/new-database/working/copy-root/000001F7/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld.semmle.00013D12 [build] [ 27% 878/3224] //external/libcxx:libc++ link libc++.dylib [darwin] [build] FAILED: out/soong/.intermediates/external/libcxx/libc++/darwin_x86_64_shared/libc++.dylib [build] prebuilts/clang/host/darwin-x86/clang-r353983c/bin/clang++ @out/soong/.intermediates/external/libcxx/libc++/darwin_x86_64_shared/libc++.dylib.rsp -force_load out/soong/.intermediates/external/libcxx/libc++_static/darwin_x86_64_static/libc++_static.a -o out/soong/.intermediates/external/libcxx/libc++/darwin_x86_64_shared/libc++.dylib -dynamiclib -single_module -install_name @rpath/libc++.dylib -target x86_64-apple-darwin -B/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.8 -m64 -ldl -lpthread -lm -nodefaultlibs -Wl,-undefined,dynamic_lookup -Wl,-rpath,@loader_path/../lib64 -Wl,-rpath,@loader_path/lib64 -nodefaultlibs -lc -lSystem -Wl,-unexported_symbols_list,external/libcxx/lib/libc++unexp.exp -Wl,-force_symbols_not_weak_list,external/libcxx/lib/notweak.exp -Wl,-force_symbols_weak_list,external/libcxx/lib/weak.exp [build] dyld: Library not loaded: @rpath/libtapi.dylib [build] Referenced from: /Volumes/v0/AOSP/new-database/working/copy-root/000001F7/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld [build] Reason: image not found [build] clang-9: error: unable to execute command: Abort trap: 6 [build] clang-9: error: linker command failed due to signal (use -v to see invocation) [build] ninja: build stopped: subcommand failed. [build] 17:09:55 ninja failed with: exit status 1 [build-err] make: *** [run_soong_ui] Error 1 [ERROR] Spawned process exited abnormally (code 2; tried to run: [/Users/user/codeql-home/codeql/tools/osx64/preload_tracer, make, services]) A fatal error occurred: Exit status 2 from command: [make, services]

Thanks for your help in advance

@matt-gretton-dann
Copy link

@matt-gretton-dann matt-gretton-dann commented Oct 19, 2020

Thank you very much for this report. To help triage can you please:

  • confirm which version of codeql you are using (codeql --version)
  • Provide information about the version of AOSP you are trying to build.

I note that macOS instructions for AOSP suggest building on a separate volume via a sparse disk-image due to case-sensitivity issues. If you are doing this can I suggest that you monitor the space available on this build volume as the CodeQL database will take a substantial amount of room. The CodeQL database does not need to live on the same volume as the build - so feel free to put it elsewhere (I usually use /tmp).

And finally, what happens if you run:

TEMPORARY_DISABLE_PATH_RESTRICTIONS=true codeql database create /tmp/new-database2 --language=java --command='make services'

(This disables some new restrictions AOSP is adding - see https://android.googlesource.com/platform/build/+/master/Changes.md#PATH_Tools).

@to-the-batmobile
Copy link
Author

@to-the-batmobile to-the-batmobile commented Oct 20, 2020

Hi Mat, thanks for the quick response!
codeql --version:
codeql --version CodeQL command-line toolchain release 2.3.1.
For example, I'm trying to build android 10 r11.
And I also compiled it successfully without codeql.
This the result of your command, seems like the build succeeds but the finalizing process fails.
Finalizing database at /tmp/new-database2. [build-err] Scanning for files in /Volumes/v0/android-10.0.0_r11... [build-err] /tmp/new-database2: Indexing files in in /Volumes/v0/android-10.0.0_r11... [build-err] /tmp/new-database2: Running in /Volumes/v0/android-10.0.0_r11: [/Users/user/codeql-home/codeql/xml/tools/index-files.sh, /tmp/new-database2/working/files-to-index13111614080267729321.list] [build] [2020-10-20] [build] [2020-10-19 17:56:50] [ERROR] Parsing error in file /Volumes/v0/android-10.0.0_r11/development/samples/training/basic/FragmentBasics/AndroidManifest.xml [build] [2020-10-20] [build] com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs. [build] [2020-10-20] [build] at [row,col {unknown-source}]: [16,5] [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:605) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:467) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary(BasicStreamReader.java:3917) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2055) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.parse(StAXXmlPopulator.java:307) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.doit(StAXXmlPopulator.java:192) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.extractFile(XmlExtractor.java:84) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.extract(SimpleExtractor.java:156) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.run(SimpleExtractor.java:52) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.main(XmlExtractor.java:29) [build] [2020-10-20] [build] 17:56:50.425 [main] ERROR com.semmle.extractor.xml.StAXXmlPopulator - Parsing error in file /Volumes/v0/android-10.0.0_r11/development/samples/training/basic/FragmentBasics/AndroidManifest.xml [build] [2020-10-20] [build] com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs. [build] [2020-10-20] [build] at [row,col {unknown-source}]: [16,5] [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:605) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:467) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary(BasicStreamReader.java:3917) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2055) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.parse(StAXXmlPopulator.java:307) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.doit(StAXXmlPopulator.java:192) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.extractFile(XmlExtractor.java:84) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.extract(SimpleExtractor.java:156) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.run(SimpleExtractor.java:52) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.main(XmlExtractor.java:29) [build] [2020-10-20] [build] [2020-10-19 17:56:53] [ERROR] Parsing error in file /Volumes/v0/android-10.0.0_r11/tools/apkzlib/src/test/resources/testData/packaging/AndroidManifest.xml [build] [2020-10-20] [build] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x9c (at char #5, byte #-1) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.throwFromIOE(StreamScanner.java:683) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1086) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.parse(StAXXmlPopulator.java:307) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.doit(StAXXmlPopulator.java:81) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.extractFile(XmlExtractor.java:84) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.extract(SimpleExtractor.java:156) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.run(SimpleExtractor.java:52) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.main(XmlExtractor.java:29) [build] [2020-10-20] [build] Caused by: java.io.CharConversionException: Invalid UTF-8 start byte 0x9c (at char #5, byte #-1) [build] [2020-10-20] [build] at com.ctc.wstx.io.UTF8Reader.reportInvalidInitial(UTF8Reader.java:302) [build] [2020-10-20] [build] at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:188) [build] [2020-10-20] [build] at com.ctc.wstx.io.ReaderSource.readInto(ReaderSource.java:84) [build] [2020-10-20] [build] at com.ctc.wstx.io.BranchingReaderSource.readInto(BranchingReaderSource.java:57) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.loadMore(StreamScanner.java:967) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.getNext(StreamScanner.java:738) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:1995) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) [build] [2020-10-20] [build] ... 6 common frames omitted [build] [2020-10-20] [build] 17:56:53.165 [main] ERROR com.semmle.extractor.xml.StAXXmlPopulator - Parsing error in file /Volumes/v0/android-10.0.0_r11/tools/apkzlib/src/test/resources/testData/packaging/AndroidManifest.xml [build] [2020-10-20] [build] com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x9c (at char #5, byte #-1) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.throwFromIOE(StreamScanner.java:683) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1086) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.parse(StAXXmlPopulator.java:307) [build] [2020-10-20] [build] at com.semmle.extractor.xml.StAXXmlPopulator.doit(StAXXmlPopulator.java:81) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.extractFile(XmlExtractor.java:84) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.extract(SimpleExtractor.java:156) [build] [2020-10-20] [build] at com.semmle.cli.SimpleExtractor.run(SimpleExtractor.java:52) [build] [2020-10-20] [build] at com.semmle.cli.XmlExtractor.main(XmlExtractor.java:29) [build] [2020-10-20] [build] Caused by: java.io.CharConversionException: Invalid UTF-8 start byte 0x9c (at char #5, byte #-1) [build] [2020-10-20] [build] at com.ctc.wstx.io.UTF8Reader.reportInvalidInitial(UTF8Reader.java:302) [build] [2020-10-20] [build] at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:188) [build] [2020-10-20] [build] at com.ctc.wstx.io.ReaderSource.readInto(ReaderSource.java:84) [build] [2020-10-20] [build] at com.ctc.wstx.io.BranchingReaderSource.readInto(BranchingReaderSource.java:57) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.loadMore(StreamScanner.java:967) [build] [2020-10-20] [build] at com.ctc.wstx.sr.StreamScanner.getNext(StreamScanner.java:738) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:1995) [build] [2020-10-20] [build] at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) [build] [2020-10-20] [build] ... 6 common frames omitted

@matt-gretton-dann
Copy link

@matt-gretton-dann matt-gretton-dann commented Oct 20, 2020

Thank you for the update. I have managed to reproduce the original issue with AOSP master (Disallowed PATH tool) myself and have a fix in progress.

I have not managed to reproduce the second issue yet.

@to-the-batmobile
Copy link
Author

@to-the-batmobile to-the-batmobile commented Oct 21, 2020

Hi Matt, can I do something to help you reproduce the second issue?

@matt-gretton-dann
Copy link

@matt-gretton-dann matt-gretton-dann commented Oct 22, 2020

@to-the-batmobile: I'm interested in the following behaviours:

  1. What command does codeql database create think it is running? (Near the top of the output from codeql there will be a line:
Running command [.*] in .*.

I'd like to know what that says.

  1. What is the disk usage like?

  2. What happens if you add -j1 to the options you pass to the make command?

@matt-gretton-dann
Copy link

@matt-gretton-dann matt-gretton-dann commented Oct 22, 2020

For reference here are the commands I have been using to try and reproduce (cribbed from https://source.android.com/setup):

# Install dependencies - Linux Only
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

# Set disk and install dependencies (macOS only)
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 250g ~/android.dmg.sparseimage
brew install git gnupg2

# Install repo
LOCAL_BIN=$HOME/bin
mkdir -p ${LOCAL_BIN}
PATH=${LOCAL_BIN}:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ${LOCAL_BIN}/repo
chmod a+x ${LOCAL_BIN}/repo

# macOS setup for each session
hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;
ulimit -S -n 1024
cd /Volumes/android

# Download source
# Make sure you have >250 GB free....
mkdir aosp
cd aosp

repo init -u https://android.googlesource.com/platform/manifest

# The -j here really is limited by your network bandwidth...
repo sync -c -j4
# Make a cup of tea

# Do a build under CodeQL
source build/envsetup.sh
# For my checkout of AOSP `make` has been made an alias - the `-c` option here is an expansion of that alias.
codeql database create -l java -c "`pwd`/build/soong/soong_ui.bash --make-mode -j1 services" /tmp/aosp-db-java
@to-the-batmobile
Copy link
Author

@to-the-batmobile to-the-batmobile commented Oct 26, 2020

@matt-gretton-dann
Hi, I tried your last command but I still get the same error, maybe it's a parsing issue that only exists in OSX?

@to-the-batmobile
Copy link
Author

@to-the-batmobile to-the-batmobile commented Oct 26, 2020

The disk usage is enough, I also compiled it successfully without codeql

@hmakholm
Copy link
Contributor

@hmakholm hmakholm commented Oct 26, 2020

(Note: Matt is out of office but may be able to get back to this next week).

@to-the-batmobile
Copy link
Author

@to-the-batmobile to-the-batmobile commented Oct 26, 2020

@hmakholm Thanks! is there a possibility that one of you guys may be able to take a quick look into this? I bet it's encoding/parsing-related issues... I'm trying to dig into the code and realize by myself but I think you might be able to also assist regarding this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.