Changes between Initial Version and Version 1 of Ticket #61784, comment 4
- Timestamp:
- Jan 30, 2021, 8:26:24 AM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #61784, comment 4
initial v1 10 10 is available writes `#define HAVE_STAT64 1`. 11 11 12 This code does this by creating a C program and then compiles, links and13 runs it.12 This code does this by creating a C program `conftest.c` and then compiles, 13 links and runs it. 14 14 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. 15 This C program does not pick up the absence of the symbol at compile time, but 16 only at link time. i.e. by defining a `char stat64 ();`, a compile only will 17 not fail with an unknown symbol. 19 18 20 On the systems tested, `stat64` is defined as a symbol in 19 See the code example 1 below and try the following on either a Silicon or Intel 20 Mac. 21 22 == Test 1 – using Joe symbol 23 24 Change all occurrences of `stat64` to `Joe` and compie without linking by 25 using `gcc -S sample.c`. This will report no errors. This is because we have 26 `char Joe ();`. 27 28 However if we compile and link `gcc sample.c -o sample`, it fails with a 29 linking error because it cannot find symbol `Joe` at link time. 30 31 == Test 2 – using stat64 symbol 32 33 Try the same two tests using `stat64` rather than `Joe`. 34 35 Both the compile only and compile/link will work on both Silicon and Intel. 36 37 The compile works because we have a `char stat64 ();`. 38 39 On the both systems tested, the link works because `stat64` is defined as a 40 symbol in `/usr/lib/dyld` which can be seen using 21 41 22 42 {{{ … … 24 44 }}} 25 45 26 So the test always return true. 46 In other words, the `gcc conftest.c` test will always return true if the symbol 47 it is testing for can be resolved at link time. 27 48 28 On the Intel Mac, compiling code generates deprecation warnings, but still 29 compiles and runs. 49 == How does this affect the pv port? 30 50 31 On the Silicon Mac, compiling generates a compile warning.51 The `pv` port uses and needs stat64. 32 52 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. 53 The code in the pv include `ifndef HAVE_STAT64` does not actually evaluate to 54 true, so the redefinition of `stat64` to `stat` does not happen here. 37 55 38 However, this compile definition is now not working on the Silicon Mac. 56 On Intel Macs, the `stat64` is redefined to `stat` by standard Apple 57 includes, but compiles with deprecation warnings, but still links and runs. 39 58 40 So we have to explicitly add a test in for this i.e. `# if __arm64__`. 59 On the Silicon Mac, the `stat64` is not redefined to `stat` by 60 standard Apple includes, so compiling `pv` code generates a compile 61 warning. 41 62 42 == Test code generated by configure 63 This is demonstrated by compiling, linking and running code example 2. 64 65 So we have to explicitly add a set of defines for this that will run 66 on 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 43 77 {{{ 44 78 /* confdefs.h */ … … 89 123 } 90 124 }}} 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 140 int 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