[libc-commits] [libc] [libc] Make use of 32-bit time_t a config option (PR #102012)

Simon Tatham via libc-commits libc-commits at lists.llvm.org
Tue Aug 6 04:14:18 PDT 2024


statham-arm wrote:

> For the other problem that other headers inside `libc/include/` also directly include `time_t`, I can think of a solution, that is directly copy either `time_t_64.h`/`time_t_32.h` to `libc/include/llvm-libc-types/time_t.h` instead.
> 
> And I think this might be a simpler solution: is you do the selection and copy to `time_t.h` in the same folder, before `add_header(time_t HDR time_t.h DEPENDS <copy_command>)`. And in that case, you will not need to update proxy headers or add extra compile options. WDYT?

To check I've understood correctly, do you mean copying one of my two time_t header files to the path `libc/include/llvm-libc-types/time_t.h` in the _source_ tree, rather than the build directory?

I'd rather avoid that if possible, because it's often useful to be able to do multiple out-of-tree builds from the same source directory with different configurations. So involving the source tree in your build in any way that is not read-only is dangerous.

(I was already a bit culture-shocked by the part of the libc build that auto-updated `libc/docs/configure.rst` when I edited `config.json`! But that only violates the _letter_ of this principle, not the spirit: the change it made in the source directory isn't specific to any build configuration.)

But I take your point about headers in the source `libc/include` subdir transitively including each other in a way that doesn't pay attention to my selection operation in the build dir. Certainly there needs to be _some_ answer to that.

When I first started looking at this problem, my first guess was that there would be an autogenerated header file called something like `llvm-libc-config.h`, similar to `libcxx/include/__config_site`, where you could write macro definitions of things discovered at cmake configure time. Then I could have written something into that file like `#define __LIBC_COPT_TIME_T_IS_64_BIT`, and `time_t.h` could have checked that ifdef instead of `__arm__` (or perhaps as well) to decide on its time_t definition, and everyone would be happy -- that macro definition would be available to the libc build _and_ to user applications including the headers. But as far as I can see there is no such config header in libc.

That said: I don't think I personally have any use case for wanting to do multiple out-of-tree builds from the same source directory with different sizes of time_t. I do want to do lots of builds from the same source dir, but they're all embedded, and I'll want all of them to have 64-bit time_t. So if you really think writing to the source dir is the best thing in this case, I don't think it'll inconvenience me _too_ much.

https://github.com/llvm/llvm-project/pull/102012


More information about the libc-commits mailing list