[libc] Provide `getenv` and other environment related symbols for bare metal targets
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I'm currently trying to port [mimalloc](https://github.com/microsoft/mimalloc) to bare metal targets, linking against different libcs. `getenv`, which is provided by picolibc, newlib and newlib-nano, is missing from llvmlibc. I [tried my hand](https://github.com/omegametabroccolo/llvm-project/commit/64e2e5ae520fd4fc41e801f714c0013dc51d2f80) at patching it, but my attempt crashes during the first call to `EnvironmentManager::get_instance` (I probably just forgot something dumb).
Before going further, there are a few things I'd like to discuss:
- In my current attempt, I set `app.env_ptr` to `nullptr` with the intent that `EnvironmentManager` immediately starts to manage the environment's memory. Maybe we could use a symbol like `__llvm_libc_environ` so that vendors can define their own initial environment?
- @kaladron I see that you implemented `setenv` and `unsetenv` under `src/stdlib/linux`, unlike `getenv` which is under `src/stdlib`, why is that? My understanding is that `{un,}setenv` only rely on `EnvironmentManager`, which can support any target with an `AppProperties app` struct that has a `uintptr_t *env_ptr` field, but maybe I'm missing something.
- I think we could also provide *env for `uefi` in the same way.
Thanks!
Contributor guide
Research direction
Start by reading EnvironmentManager::get_instance, the app.env_ptr handling, and the existing implementations under src/stdlib and src/stdlib/linux. Compare getenv with setenv and unsetenv, then investigate how UEFI support could use the same approach. Done means the supported environment-related symbols work for bare metal targets with a defined way to initialize or provide the environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100