Dynamic Modification of Build Libraries in PlatformIO

I know how to use mbedtls when building a project in PlatformIO.
I want to modify the mbedtls code so that when PlatformIO builds, it uses the modified mbedtls.a file that I created.

Currently, I have cloned the mbedtls repository from GitHub, modified the code, and after running cmake and make, I placed the resulting libmbedtls.a, libmbedcrypto.a, and libmbedx509.a files in the Project/lib directory. I also added the following build_flags:
build_flags=-Llib -lmbedtls -lmbedcrypto -lmbedx509

However, I encountered a massive number of error codes.
Some of the errors include:

/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_cli.c.obj): in function `ssl_parse_new_session_ticket':
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/mbedtls/mbedtls/library/ssl_cli.c:4182: undefined reference to `mbedtls_free'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/mbedtls/mbedtls/library/ssl_cli.c:4183: undefined reference to `mbedtls_calloc'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_srv.c.obj):(.literal.ssl_parse_client_dh_public+0x0): undefined reference to `mbedtls_dhm_read_public'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_srv.c.obj):(.literal.ssl_parse_client_psk_identity+0xc): undefined reference to `mbedtls_ct_memcmp'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_srv.c.obj):(.literal.ssl_parse_encrypted_pms+0x8): undefined reference to `mbedtls_pk_get_bitlen'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_srv.c.obj):(.literal.ssl_parse_encrypted_pms+0xc): undefined reference to `mbedtls_pk_can_do'
/Users/hanho/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /Users/hanho/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libmbedtls_2.a(ssl_srv.c.obj):(.literal.ssl_parse_encrypted_pms+0x10): undefined reference to `mbedtls_pk_decrypt'

I don’t have a solution to your question, but would like to know the reason why you want to modify the libmbedtls (during the build process)?

I want to modify the AES in mbedtls slightly and proceed with the build.

However, I don’t have enough time to rewrite all the AES code, so I want to use the AES interface provided by mbedtls and replace it with my encryption algorithm.

Yes, but what is the reason for this?
What do you want to acheive?

I want to use my custom encryption algorithm for TLS communication.

To achieve this, I need to modify the contents of mbedtls.a that is used during the build process.

I’m no expert, but I don’t think this is possible.
Afaik an .a file is an archive file of multiple .o (allready compiled object) files.

Can’t I ignore the static library I used in the previous build in platformio.ini and overwrite it with the one I made?