carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Include `LLVM_SYMBOLIZER_PATH` when running Carbon in Compiler explorer?

Open danakj opened this issue 8 months ago • 5 comments

Description of the bug:

Currently if you crash Carbon in compiler explorer you get a stack trace without symbols, which ends up in a bug report https://github.com/carbon-language/carbon-lang/issues/5094

Expecting folks playing in compiler explorer to set up a toolchain to get a stack trace seems like a reach. If it's possible it'd be nice to set LLVM_SYMBOLIZER_PATH in compiler explorer so that the stack trace is immediately useful.

danakj avatar Mar 10 '25 17:03 danakj

cc: @mattgodbolt can perhaps comment if this is possible or not

danakj avatar Mar 10 '25 17:03 danakj

This is absolutely possible yes. We can add an option in the carbon configuration to point at a symbolizer (which one?) and the code https://github.com/compiler-explorer/compiler-explorer/blob/main/lib/compilers/carbon.ts can add it to the environment variables of the process that's executed.

mattgodbolt avatar Mar 10 '25 17:03 mattgodbolt

Cool, it looks like the nightly release has the symbolizer at lib/carbon/llvm/bin/llvm-symbolizer

danakj avatar Mar 10 '25 18:03 danakj

I took a stab at this but for some reason setting LLVM_SYMBOLIZER_PATH to the path to the llvm-symbolizer symlink is just not working.

Here's the diff I was using locally (on top of https://github.com/compiler-explorer/compiler-explorer/pull/7495 so that I could run the toolchain in a local compiler explorer dev instance):

diff --git a/lib/compilers/carbon.ts b/lib/compilers/carbon.ts
index fcc868c2..104c4e33 100644
--- a/lib/compilers/carbon.ts
+++ b/lib/compilers/carbon.ts
@@ -83,6 +83,14 @@ export class CarbonCompiler extends BaseCompiler {
         execOptions: ExecutionOptionsWithEnv,
         filters?: ParseFiltersAndOutputOptions,
     ): Promise<CompilationResult> {
+        // The llvm-symbolizer is at ../lib/carbon/llvm/bin, relative to the
+        // compiler.
+        const dirIndex = this.compiler.exe.lastIndexOf('/');
+        const parentDirIndex = this.compiler.exe.lastIndexOf('/', dirIndex - 1);
+        const parentDirPath = this.compiler.exe.substring(0, parentDirIndex);
+        const symbolizer = parentDirPath + '/lib/carbon/llvm/bin/llvm-symbolizer';
+        execOptions.env['LLVM_SYMBOLIZER_PATH'] = symbolizer;
+
         const result = await super.runCompiler(compiler, options, inputFilename, execOptions, filters);
         if (result.code !== 0) return result;
         if (filters?.binary) {
  • If I point it at my system's llvm-symbolizer ('/bin/llvm-symbolizer-17') then it works and symbolizes.
  • If I run /opt/compiler-explorer/carbon-trunk/lib/carbon/llvm/bin/llvm-symbolizer --help it runs and says it is llvm-symbolizer.
  • If I point it at a symlink to /bin/llvm-symbolizer-17 that also works, so it's not a symlink issue. Maybe a busybox issue somehow. Maybe it tries to follow the symlink before executing it.

danakj avatar Mar 11 '25 16:03 danakj

@chandlerc narrowed down the issue in #infra

The busybox tries to figure out the install location from argv[0], but llvm is running the symbolizer with argv[0] of llvm-symbolizer as if it was found in the PATH, even if it was not. So the busybox can't find the install path, which doesn't matter for this command anyway, but it errors out.

danakj avatar Mar 11 '25 17:03 danakj

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term issue label can also be added for issues which are expected to take time.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Jun 10 '25 02:06 github-actions[bot]

🎉

mattgodbolt avatar Jun 12 '25 16:06 mattgodbolt

I believe there is some work to do in compiler explorer still, as the llvm-symbolizer binary isn't present in the PATH, and we need to set the LLVM_SYMBOLIZER_PATH or PATH appropriately. Fuzzer gave us a test case to try one this PR gets into the nightly release: https://carbon.godbolt.org/z/v8z7cxq8M

danakj avatar Jun 12 '25 17:06 danakj

I believe there is some work to do in compiler explorer still

Specifically, something like the diff in https://github.com/carbon-language/carbon-lang/issues/5096#issuecomment-2714966723

danakj avatar Jun 12 '25 17:06 danakj

@danakj See #5643, I think you might be missing the part about the LLVM_SYMBOLIZER_PATH setting; also see https://github.com/carbon-language/carbon-lang/pull/5643/files#diff-43757b68f1a17e454fdb4e912d71a2ea54fa8cd3438679629433976ac88a01b5

jonmeow avatar Jun 12 '25 18:06 jonmeow

Oh! I see, okay thanks!

danakj avatar Jun 12 '25 18:06 danakj