tpm2-software / tpm2-tss

OSS implementation of the TCG TPM2 Software Stack (TSS2)
https://tpm2-software.github.io
BSD 2-Clause "Simplified" License
753 stars 365 forks source link

[Bug]: Tpm2-tss library build failure #2304

Closed roychowdhuryrohit-dev closed 2 years ago

roychowdhuryrohit-dev commented 2 years ago

What happened?

PROBLEM

When tpm2-tss library is built during Snapcraft build step using make, it produces the following error.

Screenshot 2022-02-08 at 03 56 58

What is expected ?

It should install the tpm2-tss library successfully so that following condition is satisfied.

https://github.com/archethic-foundation/archethic-node/blob/8c68da5f20286a0c46d233fedc2ac7fec1a6d86d/Makefile#L12

AndreasFuchsTPM commented 2 years ago

Looks like you're trying to link a static version. And the static libcrypto.a seams to require pthread... Could this be ?

roychowdhuryrohit-dev commented 2 years ago

@AndreasFuchsSIT The same process runs successfully during native build but when I try to run the make build as a part of Snapcraft build this error occurs. Do I need to install any dependency from apt for pthread library? I have already installed autoconf-archive and libpthread-stubs0-dev.

AndreasFuchsTPM commented 2 years ago

libc6-dev (on ubuntu 20.04) contains the libpthreat.a Additionally you need to add -lpthreat to the end of your compile.

But I honestly doubt that you want to compile statically. According to your script you want to get the shared object. So something is misconfigured here.

You could post the output of make V=1 so we can see the actual compiler invocation. Also your parameters for ./configure would be interesting (line 7 in file config.log)

roychowdhuryrohit-dev commented 2 years ago
  1. libc6-dev is already installed but the issue still occurs.
  2. Where do I pass the pthread flag for gcc? I am running the following commands to build and install the library.
    ./configure --with-udevrulesdir=/etc/udev/rules.d
    make -j$(nproc)
    sudo make install
    sudo sed -i "s/tss/$(whoami)/gi" /etc/udev/rules.d/tpm-udev.rules
    sudo udevadm control --reload-rules && sudo udevadm trigger
    sudo ldconfig
    sudo apt install tpm2-tools

    The error occurs at line 2.

  3. Output file of make V=1. log.txt
AndreasFuchsTPM commented 2 years ago

Ok, I guess I don't get it. Your log.txt shows a complete and error-free build...

roychowdhuryrohit-dev commented 2 years ago

Ok, I guess I don't get it. Your log.txt shows a complete and error-free build...

Specifically libpthread.so.0 is missing in ~/parts/part_name/install/lib/x86_64-linux-gnu/ (the path used by Snapcraft during override-build) but present inside /usr/lib/x86_64-linux-gnu/. I checked with dpkg -L and the tpm build dependencies are all getting installed at /usr/lib/* but during build time Snapcraft only uses header files from ~/parts/part_name/install/lib/x86_64-linux-gnu/ which I found out from the Makefile generated by configure script.

Can you tell how does the configure script scan dependency paths and where to look for? ./configure --with-udevrulesdir=/etc/udev/rules.d

roychowdhuryrohit-dev commented 2 years ago

Turns out Snapcraft overrides env variables like CXXFLAGS and LDFLAGS on its own to set -isystem directories. Resetting them fixed the issue.