Changes between Initial Version and Version 1 of Ticket #61784, comment 4


Ignore:
Timestamp:
Jan 30, 2021, 8:26:24 AM (3 years ago)
Author:
mhberger
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #61784, comment 4

    initial v1  
    1010is available writes `#define HAVE_STAT64 1`.
    1111
    12 This code does this by creating a C program and then compiles, links and
    13 runs it.
     12This code does this by creating a C program `conftest.c` and then compiles,
     13links and runs it.
    1414
    15 This C program does not check for the presence of the symbol at compile time,
    16 but only at link time. See the code sample below. Changing all occurrences of
    17 `stat64` to `joe` and the compiling using `gcc -S sample.c` works. However
    18 `gcc sample.c -o sample` will fail with a linking error.
     15This C program does not pick up the absence of the symbol at compile time, but
     16only at link time. i.e. by defining a `char stat64 ();`, a compile only will
     17not fail with an unknown symbol.
    1918
    20 On the systems tested, `stat64` is defined as a symbol in
     19See the code example 1 below and try the following on either a Silicon or Intel
     20Mac.
     21
     22== Test 1 – using Joe symbol
     23
     24Change all occurrences of `stat64` to `Joe` and compie without linking by
     25using `gcc -S sample.c`. This will report no errors. This is because we have
     26`char Joe ();`.
     27
     28However if we compile and link `gcc sample.c -o sample`, it fails with a
     29linking error because it cannot find symbol `Joe` at link time.
     30
     31== Test 2 – using stat64 symbol
     32
     33Try the same two tests using `stat64` rather than `Joe`.
     34
     35Both the compile only and compile/link will work on both Silicon and Intel.
     36
     37The compile works because we have a `char stat64 ();`.
     38
     39On the both systems tested, the link works because `stat64` is defined as a
     40symbol in `/usr/lib/dyld` which can be seen using
    2141
    2242{{{
     
    2444}}}
    2545
    26 So the test always return true.
     46In other words, the `gcc conftest.c` test will always return true if the symbol
     47it is testing for can be resolved at link time.
    2748
    28 On the Intel Mac, compiling code generates deprecation warnings, but still
    29 compiles and runs.
     49== How does this affect the pv port?
    3050
    31 On the Silicon Mac, compiling generates a compile warning.
     51The `pv` port uses and needs stat64.
    3252
    33 The code in the pv include `ifndef HAVE_STAT64` does not actually
    34 evaluate to true, so the redefinition of `stat64` to `stat` does not happen
    35 here. Instead it is being catered for in one of the Apple libraries, but
    36 generates deprecation warnings.
     53The code in the pv include `ifndef HAVE_STAT64` does not actually evaluate to
     54true, so the redefinition of `stat64` to `stat` does not happen here.
    3755
    38 However, this compile definition is now not working on the Silicon Mac.
     56On Intel Macs, the `stat64` is redefined to `stat` by standard Apple
     57includes, but compiles with deprecation warnings, but still links and runs.
    3958
    40 So we have to explicitly add a test in for this i.e. `# if __arm64__`.
     59On the Silicon Mac, the `stat64` is not redefined to `stat` by
     60standard Apple includes, so compiling `pv` code generates a compile
     61warning.
    4162
    42 == Test code generated by configure
     63This is demonstrated by compiling, linking and running code example 2.
     64
     65So we have to explicitly add a set of defines for this that will run
     66on Silicon and not on Intel i.e. `# if __arm64__`.
     67
     68{{{
     69# if __arm64__
     70#  define stat64 stat
     71#  define fstat64 fstat
     72#  define lstat64 lstat
     73# endif
     74}}}
     75
     76== Example 1 – Test code generated by configure
    4377{{{
    4478/* confdefs.h */
     
    89123}
    90124}}}
     125
     126== Example 2 – Simple program showing use of stat64
     127{{{
     128#include <sys/types.h>
     129#include <sys/stat.h>
     130#include <stdio.h>
     131
     132// If following block is uncommented, program compiles, links and runs on Intel
     133//   (with deprecation warnings) and Silicon.
     134// If following block is commented out (leading //), then it compiles, links
     135//   and runs on Intel (with deprecation warnings) but fails to compile on Silicon
     136#if __arm64__
     137#define stat64 stat
     138#endif
     139
     140int main() {
     141  struct stat64 info;
     142
     143  if (stat64("/", &info) != 0)
     144    perror("stat() error");
     145  else {
     146    puts("stat() returned the following information about root f/s:");
     147    printf("  inode:   %d\n",   (int) info.st_ino);
     148    printf(" dev id:   %d\n",   (int) info.st_dev);
     149    printf("   mode:   %08x\n",       info.st_mode);
     150    printf("  links:   %d\n",         info.st_nlink);
     151    printf("    uid:   %d\n",   (int) info.st_uid);
     152    printf("    gid:   %d\n",   (int) info.st_gid);
     153  }
     154}
     155
     156}}}
     157