AGENTS.md
compat/openssl/AGENTS.mdAGENTS.md
Quality
58/100
Scores the file, not the repository.Length
986 words
14 headings · 6 code blocksRepository
29k
— · pushed 0 days agoLast changed
2 days ago
First indexed 2 days ago.1# compat/openssl — Guide for AI Agents23Instructions for AI agents adapting the OpenSSL compatibility layer when new BoringSSL4symbols are needed (typically after bumping gRPC, BoringSSL, or other deps).56See `README.md` in this directory for the full architectural background.78## Architecture in brief910Envoy is built against the BoringSSL API. The compat layer lets it run on OpenSSL instead.11121. **Prefixer** (`prefixer/prefixer.cpp`) copies OpenSSL headers, adding an `ossl_` prefix13 to every identifier. Output lands in `include/ossl/openssl/*.h`. It also generates14 `source/ossl.c` (forwarding functions via dlsym) and `include/ossl.h` (the `ossl` struct15 with function pointers for every real OpenSSL function).16172. **Patched BoringSSL headers** (`patch/include/openssl/*.h.sh`) start by commenting out the18 entire BoringSSL header, then selectively uncomment the symbols the compat layer exposes.19 The `uncomment.sh` tool handles this. The output is `include/openssl/*.h`.20213. **Mapping functions** (`source/*.c` or `source/*.cc`) implement each exposed BoringSSL22 function by calling the `ossl_`-prefixed OpenSSL equivalent.2324## Key files to modify2526| File | Purpose |27|------|---------|28| `patch/include/openssl/<header>.h.sh` | Controls which symbols from BoringSSL's `<header>.h` are exposed |29| `BUILD` | The `mapping_func_filegroup` list — every exposed function must be listed here |30| `source/<function>.c` or `.cc` | Handwritten mapping when auto-generation won't work |3132## How to add a missing function3334### Step 1: Uncomment the declaration3536Add `--uncomment-func-decl <function_name>` to the appropriate `.h.sh` patch script.3738Example in `ssl.h.sh`:39```bash40 --uncomment-func-decl SSL_get_negotiated_group \41```4243### Step 2: Add to the BUILD file4445Add the function name to the `mapping_func_filegroup` list (alphabetically sorted within46its section).4748### Step 3: Decide if a handwritten source file is needed4950The build system (`bazel/rules.bzl`) auto-generates a forwarding function if no handwritten51`source/<function>.c` or `.cc` exists. The generated code handles both cases — OpenSSL52macros and real functions — using an `#ifdef`:5354```c55// Auto-generated pattern:56ReturnType FunctionName(args) {57#ifdef ossl_FunctionName58 return ossl_FunctionName(args); // macro path (expands inline)59#else60 return ossl.ossl_FunctionName(args); // function pointer path (via dlsym)61#endif62}63```6465**You need a handwritten source when:**66- The BoringSSL and OpenSSL signatures differ (different arg types, arg count)67- The semantics differ (e.g., `SSL_CTX_set1_curves_list` has an OpenSSL 3.5 bug workaround)68- The function has no OpenSSL equivalent at all (must be implemented from scratch)6970**You can rely on auto-generation when:**71- The function exists in OpenSSL with the same signature (as a real function or macro)72- No semantic differences need patching7374## How to add a missing constant or macro7576### Constant exists in both BoringSSL and OpenSSL7778Add `--uncomment-macro-redef '<pattern>'` to the `.h.sh` patch script. This generates:7980```c81#ifdef ossl_CONSTANT_NAME82#define CONSTANT_NAME ossl_CONSTANT_NAME83#endif84```8586The constant gets OpenSSL's value. Use regex patterns to cover families:87```bash88 --uncomment-macro-redef 'SSL_R_[[:alnum:]_]*' \89 --uncomment-macro-redef 'OPENSSL_INIT_[[:alnum:]_]*' \90```9192### Constant exists only in BoringSSL (no OpenSSL equivalent)9394The `--uncomment-macro-redef` approach won't work because there's no `ossl_` version — the95`#ifdef` guard will be false and the constant stays undefined.9697Instead, append a standalone `#ifndef`/`#define` block at the end of the `.h.sh` script:9899```bash100cat >> "$1" <<'EOF'101102#ifndef SSL_R_SOME_BORINGSSL_ONLY_CONSTANT103#define SSL_R_SOME_BORINGSSL_ONLY_CONSTANT <value>104#endif105EOF106```107108**Choosing values:** BoringSSL and OpenSSL often use the same numeric range for different109constants. For example, BoringSSL's `SSL_R_NO_CIPHERS_PASSED = 176` collides with OpenSSL's110`SSL_R_NO_CERTIFICATES_RETURNED = 176`. If both appear in the same switch statement,111you get a duplicate-case error. To avoid this, use values in a range that neither library112uses (e.g., 10000+ for `SSL_R_*` constants). The exact values don't matter at runtime113since OpenSSL will never produce these BoringSSL-specific error codes.114115### Constant with duplicate-case-value problem116117If a constant must exist but its value collides with another constant's value (e.g.,118`ERR_R_OVERFLOW` aliased to `ERR_R_INTERNAL_ERROR`), give it a unique value. Check119OpenSSL's range for the constant family in `bazel-envoy/external/openssl/include/openssl/`120and pick a value above the highest used one.121122## uncomment.sh — common options123124| Option | Effect |125|--------|--------|126| `--uncomment-func-decl <name>` | Uncomment a function declaration |127| `--uncomment-macro '<pattern>'` | Uncomment a `#define` (keeps BoringSSL's value) |128| `--uncomment-macro-redef '<pattern>'` | Redefine macro to use OpenSSL's value via `ossl_` prefix |129| `--uncomment-enum <name>` | Uncomment an enum definition |130| `--uncomment-struct <name>` | Uncomment a struct definition |131| `--uncomment-typedef <name>` | Uncomment a typedef |132| `--uncomment-typedef-redef <name>` | Redefine a typedef to use OpenSSL's type |133| `--uncomment-regex '<pattern>'` | Uncomment lines matching a regex |134| `--uncomment-regex-range '<start>' '<end>'` | Uncomment a multi-line block |135| `--sed '<expression>'` | Run an arbitrary sed expression on the file |136137## Inspecting generated output138139To see what the compat layer actually produces after patching/prefixing, look in the bazel140output directory. The exact path depends on the build configuration:141142```143bazel-out/k8-fastbuild/bin/compat/openssl/include/openssl/<header>.h # patched BoringSSL header144bazel-out/k8-fastbuild/bin/compat/openssl/include/ossl/openssl/<header>.h # prefixed OpenSSL header145bazel-out/k8-fastbuild/bin/compat/openssl/include/ossl.h # ossl struct definition146bazel-out/k8-fastbuild/bin/compat/openssl/source/<function>.c # auto-generated mapping147```148149Check the prefixed OpenSSL headers to determine:150- Whether an `ossl_<symbol>` exists (i.e., whether `--uncomment-macro-redef` will work)151- Whether a symbol is a macro or a real function in OpenSSL152- What numeric value OpenSSL assigns to a constant153154Check the `ossl.h` struct to see which OpenSSL functions are available as function pointers155(only real functions, not macros).156157## Typical workflow for fixing build errors after a dep bump1581591. **Read the errors.** Group them by type: undeclared functions, undeclared constants,160 duplicate case values.1611622. **For each undeclared function:**163 - Check if it exists in BoringSSL (`bazel-envoy/external/boringssl/include/openssl/`)164 - Check if it exists in OpenSSL (`bazel-envoy/external/openssl/include/openssl/`)165 - Add `--uncomment-func-decl` to the patch script + entry in BUILD166 - If OpenSSL's semantics differ, write a handwritten source file1671683. **For each undeclared constant:**169 - Check if it exists in both BoringSSL and OpenSSL170 - If yes: use `--uncomment-macro-redef` in the patch script171 - If BoringSSL-only: append a `#ifndef`/`#define` with a collision-free value1721734. **For duplicate case values:**174 - Identify which constants share the same numeric value175 - Give the BoringSSL-only constant a unique value outside both libraries' ranges1761775. **Build and iterate** — new symbols may trigger further missing-symbol errors as178 more code becomes reachable.179
Also in envoyproxy/envoy
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| envoyproxy/envoy.github/copilot-instructions.md · 29k | Copilot instructions | setupbuildtestlint-format+7 | 77/100 | 2 days ago | |
| envoyproxy/envoyAGENTS.md · 29k | AGENTS.md | setupbuildtestlint-format+7 | 88/100 | 2 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| vllm-project/vllmAGENTS.md · 88k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-frontend/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-query-engine/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+5 | 98/100 | 2 days ago |
