diff --git a/configure b/configure index 67759ef53f5..db7431ce212 100755 --- a/configure +++ b/configure @@ -5412,9 +5412,9 @@ if test "$llvm" != "no"; then llvm_components="" llvm_cxxflags=$($llvm_config $llvm_components --cxxflags 2> /dev/null) - llvm_ldflags=$($llvm_config $llvm_components --ldflags 2> /dev/null) + # Add ltinfo for fixing LLVM linking error [Maybe i just messed up with LLVM compiling] + llvm_ldflags="$($llvm_config $llvm_components --ldflags 2> /dev/null) -ltinfo" llvm_libs=$($llvm_config $llvm_components --libs 2> /dev/null) - if compile_prog_clangxx "$llvm_cxxflags -Wno-unused-variable" "$llvm_libs $llvm_ldflags" ; then : LLVM found elif test "$llvm" = "yes"; then diff --git a/panda/dependencies/ubuntu_24.04_base.txt b/panda/dependencies/ubuntu_24.04_base.txt new file mode 100644 index 00000000000..2c0eaf019e9 --- /dev/null +++ b/panda/dependencies/ubuntu_24.04_base.txt @@ -0,0 +1,90 @@ +# Panda dependencies +# Note that libcapstone >= v4.1 is also required, but that's not available in apt +git +libdwarf1 +libjsoncpp-dev +# libllvm11 +libprotobuf-c-dev +libvte-2.91-0 +libwireshark-dev +libwiretap-dev +# Fixes config.h build error +wireshark-dev +libxen-dev +libz3-dev +python3 +python3-pip +wget + +# pyperipheral (only needed for armel) +libpython3-dev + +# pypanda dependencies +genisoimage +libffi-dev +python3-protobuf +python3-colorama + +# Not sure what this one is needed for +liblzo2-2 + +# apt-rdepends qemu-system-common +acl +libc6 +libcap-ng0 +libcap2 +libgbm1 +libglib2.0-0 +libglib2.0-dev +zlib1g-dev +libgnutls30 +libnettle8 +libpixman-1-0 +libvirglrenderer1 + +# apt-rdepends qemu-block-extra +libcurl3-gnutls +libglib2.0-0 +libiscsi7 +librados2 +librbd1 +libssh-4 + +# apt-rdepends qemu-system-arm, seems most of the system-[arch]es have same dependencies +libaio1t64 +libasound2t64 +libbrlapi-dev +libc6 +libcacard0 +libepoxy0 +libfdt1 +libgbm1 +libgcc-s1 +libglib2.0-0 +libgnutls30 +libibverbs1 +libjpeg8 +libncursesw6 +libnuma1 +libpixman-1-0 +libpmem1 +libpng16-16 +librdmacm1 +libsasl2-2 +libseccomp2 +libslirp0 +libspice-server1 +libstdc++6 +libtinfo6 +libusb-1.0-0 +libusbredirparser1 +libvirglrenderer1 +zlib1g + +# rr2 dependencies +libarchive-dev +libssl-dev + +# libosi build dependecies +pkg-config +libglib2.0-dev diff --git a/panda/dependencies/ubuntu_24.04_build.txt b/panda/dependencies/ubuntu_24.04_build.txt new file mode 100644 index 00000000000..8f8d472e094 --- /dev/null +++ b/panda/dependencies/ubuntu_24.04_build.txt @@ -0,0 +1,90 @@ +libc++-dev +libelf-dev +libtool-bin +libwireshark-dev +libwiretap-dev +# lsb-core +zip + +# panda build deps +# Note libcapstone-dev is required, but we need v4 + which isn't in apt +build-essential +chrpath +# clang-11 +gcc +libdwarf-dev +libprotoc-dev +# llvm-11-dev +protobuf-c-compiler +protobuf-compiler +python3-dev +libpixman-1-dev +zip + +# pypanda dependencies +python3-setuptools +python3-wheel + +# pypanda test dependencies +gcc-multilib +libc6-dev-i386 +nasm + +# Qemu build deps +debhelper +device-tree-compiler +libgnutls28-dev +libaio-dev +libasound2-dev +libattr1-dev +libbrlapi-dev +libcacard-dev +libcap-dev +libcap-ng-dev +libcurl4-gnutls-dev +libdrm-dev +libepoxy-dev +libfdt-dev +libgbm-dev +libibumad-dev +libibverbs-dev +libiscsi-dev +libjpeg-dev +libncursesw5-dev +libnuma-dev +libpmem-dev +libpng-dev +libpulse-dev +librbd-dev +librdmacm-dev +libsasl2-dev +libseccomp-dev +libslirp-dev +libspice-protocol-dev +libspice-server-dev +libssh-dev +libudev-dev +libusb-1.0-0-dev +libusbredirparser-dev +libvirglrenderer-dev +nettle-dev +python3 +python3-sphinx +texinfo +uuid-dev +xfslibs-dev +zlib1g-dev +libc6.1-dev-alpha-cross + +# qemu build deps that conflict with gcc-multilib +#gcc-alpha-linux-gnu +#gcc-powerpc64-linux-gnu +#gcc-s390x-linux-gnu + +# rust install deps +curl + +# libosi install deps +cmake +ninja-build +rapidjson-dev diff --git a/panda/plugins/network/network.cpp b/panda/plugins/network/network.cpp index 16ad8a63353..6518dfa31ce 100644 --- a/panda/plugins/network/network.cpp +++ b/panda/plugins/network/network.cpp @@ -1,15 +1,15 @@ /* PANDABEGINCOMMENT - * + * * Authors: * Tim Leek tleek@ll.mit.edu * Ryan Whelan rwhelan@ll.mit.edu * Joshua Hodosh josh.hodosh@ll.mit.edu * Michael Zhivich mzhivich@ll.mit.edu * Brendan Dolan-Gavitt brendandg@gatech.edu - * - * This work is licensed under the terms of the GNU GPL, version 2. - * See the COPYING file in the top-level directory. - * + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + * PANDAENDCOMMENT */ // This needs to be defined before anything is included in order to get // the PRIx64 macro @@ -21,6 +21,7 @@ #include #include +#include // These need to be extern "C" so that the ABI is compatible with // QEMU/PANDA, which is written in C @@ -56,7 +57,7 @@ bool init_plugin(void *self) { .snaplen = 65535, .shb_hdrs = NULL, .idb_inf = NULL, - .nrb_hdrs = NULL, + .nrbs_growing = NULL, .dsbs_initial = NULL, .dsbs_growing = NULL }; @@ -76,20 +77,19 @@ bool init_plugin(void *self) { fprintf(stderr, "Plugin 'network' needs argument: -panda-arg network:file=\n"); return false; } - + int file_type = wtap_pcapng_file_type_subtype(); #if (VERSION_MAJOR == 2 && VERSION_MINOR >= 6 ) || (VERSION_MAJOR>=3) wtap_init(false); #elif VERSION_MAJOR == 2 && VERSION_MINOR == 2 && VERSION_MICRO >= 4 wtap_init(); #endif - #if (VERSION_MAJOR>=3) #if (VERSION_MAJOR>=4 || VERSION_MINOR>=4) gchar *write_err_info; #endif plugin_log = wtap_dump_open( tblog_filename, - WTAP_FILE_TYPE_SUBTYPE_PCAPNG, + file_type, WTAP_UNCOMPRESSED, // assuming this... &wdparams, // the new structure that wraps all the ng params &err @@ -100,15 +100,15 @@ bool init_plugin(void *self) { #else plugin_log = wtap_dump_open_ng( /*filename*/tblog_filename, - /*file_type_subtype*/WTAP_FILE_TYPE_SUBTYPE_PCAPNG, + /*file_type_subtype*/file_type, /*encap*/WTAP_ENCAP_ETHERNET, /*snaplen*/65535, /*compressed*/1, /*shb_hdrs*/NULL, /*idb_inf*/NULL, - #if VERSION_MAJOR == 2 + #if VERSION_MAJOR == 2 /*nrb_hdrs*/NULL, - #endif + #endif /*err*/&err); #endif @@ -134,7 +134,8 @@ void uninit_plugin(void *self) { #endif #if (VERSION_MAJOR>=4 || (VERSION_MAJOR==3 && VERSION_MINOR>=4)) gchar *write_err_info; - gboolean ret = wtap_dump_close(plugin_log, &err, &write_err_info); + gboolean needs_reload; + gboolean ret = wtap_dump_close(plugin_log, &needs_reload, &err, &write_err_info); #else gboolean ret = wtap_dump_close(plugin_log, &err); #endif @@ -163,8 +164,8 @@ void handle_packet(CPUState *env, uint8_t *buf, size_t size, uint8_t direction, rec.rec_header.packet_header.caplen = size; rec.rec_header.packet_header.len = size; rec.rec_header.packet_header.pkt_encap = WTAP_ENCAP_ETHERNET; - rec.opt_comment = comment_buf; - rec.has_comment_changed = true; + wtap_block_t pkt_block = wtap_block_create(WTAP_BLOCK_PACKET); + wtap_block_add_string_option(pkt_block, OPT_COMMENT, comment_buf, strlen(comment_buf) + 1); ret = wtap_dump( /*wtap_dumper*/ plugin_log, /*wtap_rec*/ &rec, @@ -173,9 +174,9 @@ void handle_packet(CPUState *env, uint8_t *buf, size_t size, uint8_t direction, /*err_info*/ &err_info); #else struct wtap_pkthdr header; - #if VERSION_MAJOR >= 2 - wtap_phdr_init(&header); - #endif + #if VERSION_MAJOR >= 2 + wtap_phdr_init(&header); + #endif header.ts.secs = now_tv.tv_sec; header.ts.nsecs = now_tv.tv_usec * 1000; header.caplen = size; @@ -187,14 +188,14 @@ void handle_packet(CPUState *env, uint8_t *buf, size_t size, uint8_t direction, /*wtap_pkthdr*/ &header, /*buf*/ buf, /*err*/ &err - #if VERSION_MAJOR >= 2 + #if VERSION_MAJOR >= 2 , /*err_info*/ &err_info - #endif + #endif ); - #if VERSION_MAJOR >= 2 - wtap_phdr_cleanup(&header); - #endif + #if VERSION_MAJOR >= 2 + wtap_phdr_cleanup(&header); + #endif #endif if (!ret) { fprintf(stderr, "Plugin 'network': failed wtap_dump() with error %d", err); @@ -206,4 +207,3 @@ void handle_packet(CPUState *env, uint8_t *buf, size_t size, uint8_t direction, return; } #endif - diff --git a/panda/scripts/build_libosi.sh b/panda/scripts/build_libosi.sh new file mode 100755 index 00000000000..9ed28f04a80 --- /dev/null +++ b/panda/scripts/build_libosi.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e +echo "Building libosi..." +if [ ! -d "libosi" ]; then + git clone https://github.com/panda-re/libosi.git +else + echo "Directory 'libosi' already exists. Skipping clone." +fi + +pushd libosi +mkdir -p build && cd build +cmake -GNinja .. +ninja +ninja package +sudo dpkg -i libosi-*.deb +popd +rm -rf libosi diff --git a/panda/scripts/build_llvm.sh b/panda/scripts/build_llvm.sh new file mode 100755 index 00000000000..b79f319ee0c --- /dev/null +++ b/panda/scripts/build_llvm.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# https://gist.github.com/ouankou/27c1fc22aee9125190492ea126125249 +export LLVM_VERSION=11 +export LLVM_SRC=$HOME/llvm/llvm_src +export LLVM_PATH=$HOME/llvm/llvm_install +export LLVM_BUILD=$HOME/llvm/llvm_build +export CC=`which clang` +export CXX=`which clang++` + +mkdir -p $LLVM_SRC +mkdir -p $LLVM_PATH +mkdir -p $LLVM_BUILD + +cd $LLVM_SRC + +# Clone the repository from the old URL (replace the $LLVM_VERSION with actual version, e.g., 11) +git clone --depth 1 -b release/$LLVM_VERSION.x https://github.com/llvm/llvm-project . + +# siglans-missing-cstdint-include-patch +sed -i '/#include /a #include ' $LLVM_SRC/llvm/include/llvm/Support/Signals.h +# fix-missing-header-limits-patch +sed -i '/^#include /a #include ' $LLVM_SRC/llvm/utils/benchmark/src/benchmark_register.cc +sed -i '/^#include /a #include ' $LLVM_SRC/llvm/utils/benchmark/src/benchmark_register.h + +cd $LLVM_BUILD + +# Configure the build using CMake +cmake -G Ninja -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DLLVM_USE_LINKER=gold -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DLLVM_ENABLE_PROJECTS="clang" $LLVM_SRC/llvm + +# Build and install LLVM +# Use j1 for less memory consumption -> fixes kill clang process +ninja -j2 -l2 +ninja install -j2 + +# Update environment variables for LLVM +export PATH=$LLVM_PATH/bin:$PATH +export LD_LIBRARY_PATH=$LLVM_PATH/libexec:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=$LLVM_PATH/lib:$LD_LIBRARY_PATH +export LIBRARY_PATH=$LLVM_PATH/libexec:$LIBRARY_PATH +export LIBRARY_PATH=$LLVM_PATH/lib:$LIBRARY_PATH +export MANPATH=$LLVM_PATH/share/man:$MANPATH +export C_INCLUDE_PATH=$LLVM_PATH/include:$C_INCLUDE_PATH +export CPLUS_INCLUDE_PATH=$LLVM_PATH/include:$CPLUS_INCLUDE_PATH +export LLVM_CONFIG_BINARY=$LLVM_PATH/bin/llvm-config diff --git a/panda/scripts/install_ubuntu.sh b/panda/scripts/install_ubuntu.sh index 73b853e7281..d1ce48cd1df 100755 --- a/panda/scripts/install_ubuntu.sh +++ b/panda/scripts/install_ubuntu.sh @@ -64,7 +64,9 @@ else exit 1 fi -progress "Installing PANDA dependencies..." +progress "Installing PANDA dependencies..." +# Ignore errors +set +e # Read file in dependencies directory and install those. If no dependency file present, error $SUDO apt-get update @@ -90,6 +92,17 @@ else exit 1 fi +set -e + +if [ "$version" -eq 24 ]; then + if [ -f "$HOME/llvm/llvm_install/bin/clang" ]; then + progress "LLVM is already built in $HOME/llvm/llvm_install." + else + progress "Building LLVM..." + ./panda/scripts/build_llvm.sh + fi +fi + progress "Installing Rust..." curl https://sh.rustup.rs -sSf | sh -s -- -y @@ -107,7 +120,7 @@ if [ "$version" -eq 18 ]; then fi # Install libcapstone v5 release if it's not present -if [[ !$(ldconfig -p | grep -q libcapstone.so.5) ]]; then +if ! ldconfig -p | grep -q libcapstone.so.5; then echo "Installing libcapstone v5" pushd /tmp && \ git clone https://github.com/capstone-engine/capstone/ -b v5 && \ @@ -117,19 +130,26 @@ if [[ !$(ldconfig -p | grep -q libcapstone.so.5) ]]; then popd fi +LIBOSI_URL="https://github.com/panda-re/libosi/releases/download/v${LIBOSI_VERSION}/libosi_${UBUNTU_VERSION}.deb" + # if the windows introspection library is not installed, clone and install -if [[ !$(dpkg -l | grep -q libosi) ]]; then - pushd /tmp - curl -LJO https://github.com/panda-re/libosi/releases/download/v${LIBOSI_VERSION}/libosi_${UBUNTU_VERSION}.deb - $SUDO dpkg -i /tmp/libosi_${UBUNTU_VERSION}.deb - rm -rf /tmp/libosi_${UBUNTU_VERSION}.deb - popd +if ! dpkg -l | grep -q libosi; then + if curl --output /dev/null --silent --head --fail "${LIBOSI_URL}"; then + pushd /tmp + curl -LO "${LIBOSI_URL}" + $SUDO dpkg -i "libosi_${UBUNTU_VERSION}.deb" + rm -rf "libosi_${UBUNTU_VERSION}.deb" + popd + else + echo "Realse libosi not found. Building from source..." + ./panda/scripts/build_libosi.sh + fi fi # PyPANDA needs CFFI from pip (the version in apt is too old) # Install system-wide since PyPANDA install will also be system-wide -$SUDO python3 -m pip install pip -$SUDO python3 -m pip install "cffi>1.14.3" +$SUDO python3 -m pip install --break-system-packages pip +$SUDO python3 -m pip install --break-system-packages "cffi>1.14.3" progress "Trying to update DTC submodule" git submodule update --init dtc || true @@ -147,7 +167,7 @@ pushd build progress "PANDA is built and ready to use in panda/build/[arch]-softmmu/panda-system-[arch]." cd ../panda/python/core -$SUDO python3 -m pip install -r requirements.txt +$SUDO python3 -m pip install --break-system-packages -r requirements.txt $SUDO python3 setup.py install python3 -c "import pandare; panda = pandare.Panda(generic='i386')" # Make sure it worked progress "Pypanda successfully installed"