chmod() is no longer implemented?

fschuetz
Posts: 9
Joined: Thu Sep 17, 2020 10:37 pm

chmod() is no longer implemented?

Postby fschuetz » Thu Aug 08, 2024 10:54 am

I needed some additional functionality to what the framework implementation of lib linenoise offered. In my adaption I used a function call to chmod when storing the history file. All compiled well up to and including espidf 5.2. However, with espidf 5.3 I get linker errors:

Code: Select all

Creating esp32s3 image...
Merged 2 ELF sections
Successfully created esp32s3 image.
Linking .pio/build/BCD-0o26-5KY/firmware.elf
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: .pio/build/BCD-0o26-5KY/esp-idf/ch405labs_linenoise/libch405labs_linenoise.a(ch405labs_linenoise.c.o):(.literal.ch405_labs_linenoiseHistorySave+0x1c): warning: chmod is not implemented and will always fail
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: .pio/build/BCD-0o26-5KY/esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.o):(.literal.mbedtls_x509_crt_parse_path+0x28): warning: readdir is not implemented and will always fail
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: .pio/build/BCD-0o26-5KY/esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.o):(.literal.mbedtls_x509_crt_parse_path+0x2c): warning: closedir is not implemented and will always fail
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: .pio/build/BCD-0o26-5KY/esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.o):(.literal.mbedtls_x509_crt_parse_path+0x10): warning: opendir is not implemented and will always fail
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `opendir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:16: multiple definition of `opendir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:733: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `closedir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/src/newlib-git-7cdcb0b0/newlib/libc/include/dirent.h:76: multiple definition of `closedir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:805: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `mkdir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:30: multiple definition of `mkdir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:818: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `readdir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/src/newlib-git-7cdcb0b0/newlib/libc/include/dirent.h:56: multiple definition of `readdir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:750: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `telldir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/src/newlib-git-7cdcb0b0/newlib/libc/include/dirent.h:73: multiple definition of `telldir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:776: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `seekdir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:73: multiple definition of `seekdir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:789: first defined here
/Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /Users/fschuetz/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/libnosys.a(dir.o): in function `rewinddir':
/Users/brnomac003/.gitlab-runner/builds/qR2TxTby/0/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:101: multiple definition of `rewinddir'; .pio/build/BCD-0o26-5KY/esp-idf/vfs/libvfs.a(vfs.c.o):/Users/fschuetz/.platformio/packages/framework-espidf/components/vfs/vfs.c:800: first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/BCD-0o26-5KY/firmware.elf] Error 1
Commenting out the call to chmod() results in clean linking. Why is this? How can I fix that and still use chmod as a call. The code in question is:

Code: Select all

/* Save the history in the specified file. On success 0 is returned
 * otherwise -1 is returned. */
int ch405_labs_linenoiseHistorySave(const char *filename) {
    mode_t old_umask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
    FILE *fp;
    int j;

    fp = fopen(filename,"w");
    umask(old_umask);
    if (fp == NULL) return -1;
    chmod(filename,S_IRUSR|S_IWUSR);
    for (j = 0; j < history_len; j++)
        fprintf(fp,"%s\n",history[j]);
    fclose(fp);
    return 0;
}

Miaou_
Posts: 1
Joined: Tue Aug 13, 2024 2:50 pm

Re: chmod() is no longer implemented?

Postby Miaou_ » Tue Aug 13, 2024 3:27 pm

I'm working with fschuetz on this project.

We are working with the Espressif platform 6.8.0 which uses the framework-espidf 5.3.0.
The toolchain is toolchain-xtensa-esp-elf version 13.2.0+20240530.
According to the espressif/crosstool-NG repository, this toolchain is built with:

Code: Select all

CT_NEWLIB_DEVEL_URL="https://github.com/espressif/newlib-esp32.git"
CT_NEWLIB_DEVEL_BRANCH="esp-4.3.0_20240530"
Now it happens that the commit 070bbf2fe for newlib-esp32.git version 4.3.0 20240530 introduced stubs for some of the C library functions, in particular chmod, readdir, opendir, ...
This can be found in libgloss/libnosys/dir.c:
  1. int chmod(const char *path, mode_t mode)
  2. {
  3.     errno = ENOSYS;
  4.     return -1;
  5. }
  6. stub_warning(chmod)
This most probably introduces the "multiple redefinition bug" as these stubs are included in this version of newlib, but libvfs also defines these functions, because it actually implements them...

The commit which introduces the stubs in newlib is not part of a pull request so we don't know why the stubs were added.
How can we continue from here?

Who is online

Users browsing this forum: Google [Bot] and 234 guests