Skip to content

GCC linker errors not showing up in Problems window #2864

Closed

Description

@RolfNoot

Brief Issue Summary

I am not sure whether this is an issue or expected behavior. Compiler errors are shown correctly.

Schermafbeelding 2022-11-22 om 17 17 27

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

Activity

  1. bobbrow commented on Nov 22, 2022

    @bobbrow
    Contributor

    This would be a bug/feature request. We have a regular expression that matches compiler errors, but the linker errors don't match that pattern. Thanks for reporting it. We may not get to this immediately, but will accept a PR from the community if someone is able to address it before we do.

  2. added
    buga bug in the product
    help wantedwe currently are not planning work on this and would like help from the open source community
    Feature: diagnosticsissues with problem matchers for compiler output
    on Nov 22, 2022
  3. added this to the Backlog milestone on Nov 22, 2022
  4. RolfNoot commented on Nov 22, 2022

    @RolfNoot
    Author

    Thanks for the quick reply. Where (in code?) can I find this regex? I might change it according my needs.

  5. bobbrow commented on Nov 22, 2022

    @bobbrow
    Contributor

    It is here:

    export const REGEX = /^(.*):(\d+):(\d+):\s+(?:fatal )?(\w*)(?:\sfatale)?\s?:\s+(.*)/;

  6. RolfNoot commented on Nov 23, 2022

    @RolfNoot
    Author

    Changing the regex doesn't affect the output. I changed the one in vscode-cmake-tools/src/diagnostics/msvc.ts which seems to affect the output.

    How can I select the problemMatcher when starting build programmatically (not using Tasks) vscode.commands.executeCommand('cmake.build')?

  7. bobbrow commented on Nov 23, 2022

    @bobbrow
    Contributor

    I believe that all the problem matchers are active when you build with our commands (not tasks). You can control which ones are active with the cmake.enabledOutputParsers setting.

  8. evakili commented on Jan 4, 2023

    @evakili

    This issue also exists in MSVC builds. MSVC link errors are not matched by the problem matcher.

  9. denis-shienkov commented on Feb 3, 2023

    @denis-shienkov

    It is because the VSCode does not provide an API to show the problems without of a file path. I meant, that usually, the linker errors does not a file paths at all.

  10. RolfNoot commented on Feb 3, 2023

    @RolfNoot
    Author

    It can show problems using a 'null' path. Besides that, the file path is provided by the linker and should be matched by the regex (/Volumes/.../main.c:105 in this case).

    I am currently using an additional problemmatcher for linker errors which works fine.

    This should be implemented in the extension IMHO.

    "problemMatcher": [
            {
                "base": "$gcc",
                "fileLocation": ["relative", "${workspaceFolder}/build" ]
            },
            {
                "owner": "linker0",
                "severity": "error",
                "fileLocation" : "absolute",
                "pattern": {
                "regexp": "((error): ld returned (-?\\d+) exit status)",
                "message": 1,
                "file" : 2
                }
            },
            {
                "owner": "linker1",
                "severity": "error",
                "fileLocation" : "absolute",
                "pattern": {
                "regexp": "(\\S*\\..{0,2}):(\\d*):\\s(undefined reference to `\\S*')",
                "file": 1,
                "line": 2,
                "message": 3
                }
            },
            {
                "owner": "linker2",
                "severity": "error",
                "fileLocation" : "absolute",
                "pattern": {
                "regexp": "((.*\\..{0,2}):(\\d+): (multiple definition of .+);.+:(.*\\..{0,2}):(\\d+): first defined here)",
                "message": 4,
                "file": 5,
                "line": 3
                }
            },
            {
                "owner": "linker3",
                "severity": "error",
                "fileLocation" : "absolute",
                "pattern": {
                "regexp": "((cannot open linker script file (.+.ld): No such file or directory))",
                "message": 1,
                "file": 3
                }
            },
            {
                "owner": "linker4",
                "severity": "error",
                "fileLocation" : "absolute",
                "pattern": {
                "regexp": "((region `\\S+' overflowed by \\d+ bytes))",
                "message": 1
                }
            }
    
  11. denis-shienkov commented on Feb 4, 2023

    @denis-shienkov

    Besides that, the file path is provided by the linker

    This is a special case that there is a path to the file. In most cases, linking errors do not contain any paths. This will not only affect GCC but also other compilers (eg MSVC, IAR, KEIL, SDCC and etc).

    So, in a common case you can't extract the file property for the problem matcher... And, what's to do in such case is unknown..

    I even created an issue about that:

    but all was unsucessfull.

  12. RolfNoot commented on Feb 4, 2023

    @RolfNoot
    Author

    What you can do in such a case is use a 'null' path for the file.
    No file path

    In my opinion, this is currently the best way to report linker errors without file reference. Not reporting linker errors is really not a good option for most users. In the future, I hope VS Code will implement a way to implement error reporting without file reference.

  13. denis-shienkov commented on Feb 4, 2023

    @denis-shienkov

    Hmm.. Is it possible at all to set a null path? Because the vscode.DiagnosticCollection expects the the method set(uri: Uri, diagnostics: readonly Diagnostic[]): void use an vscode.Uri type. I'm not sure that it is possible to assign a null to the Uri (I'm not a typescript expert at all).

  14. 15 remaining items

  15. 0xemgy commented on Aug 1, 2024

    @0xemgy
    Contributor

    Garrett Campbell (@gcampbell-msft) v-frankwang I think I got it: Forked the repo, created a PR, agreed to the CLA: #3950

  16. 0xemgy commented on Aug 3, 2024

    @0xemgy
    Contributor

    Garrett Campbell (@gcampbell-msft) v-frankwang

    It turns out there already is a GNU linker error parser in your code base.

    The CI unit test in my PR #3950 failed because the unit test for this linker error parser failed. It now fails because my GCC error parser already finds linker errors, which resulsts in the linker error parser not being executed,

    It turns out you guys have a bug that causes errors that are detected by the linker error parser to not be pushed to the Problems View (short description of the bug: default configuration string for linker parser is "gnuld", but code uses "link", so linker errors are ignored in the function resolveDiagnostics) .
    If fixed this bug locally by changing the string "link" to "gnuld".

    Then errors detected by the linker error parser are shown in the Problems View. But the parsing does not work properly. It is too simplistic. It only detects 6 out of the 12 linker errors I use for testing, and 3 out of these 6 findings are parsed incorrectly (e.g. path/to/ld.exe:path/to/file:138: syntax error is detected, but the file name path/to/ld.exe:path/to/file is parsed instead of path/to/file).

    So I suggest I fix the described bug and move the linker errors that I implemented in the GCC parser to the linker parser, and also add some unit tests for all the error strings I use for testing.

    I also would like to test this new solution at work for a few weeks to make sure I did not break anything.
    I think I need to test it for a while because the parsing order is actually relevant. E.g. a linker error of type path/to/ld[.exe]:path/to/file:line: warning: memory region ... not declared would be falsely detected as a GCC compiler error of type path/to/file:line: severity: message` if the compiler errors are parsed prior to the linker errors. I already regarded this in my local fix by changing the parser execution order (linker parser is now executed before the compiler parser). But I prefer to test this a little further.

    Are you guys fine with that or do you prefer my current solution with linker error parsing in the GCC parser and want to delete the separate linker error parser?

  17. RolfNoot commented on Aug 3, 2024

    @RolfNoot
    Author

    I like to test as well, working a lot with gcc. Is there a repo or .vsix to test it?

  18. 0xemgy commented on Aug 4, 2024

    @0xemgy
    Contributor

    RolfNoot I created a new branch in my forked repo, see branch dev/0xemgy/FixGnuLdProblemsViewPrompt here, with the solution I'm confident Garrett Campbell (@gcampbell-msft) will prefer (keeping the gnu ld parser).

    I generated a vsix (with local changes to the version in package.json to 99.99.0):
    cmake-tools-99.99.0.vsix.zip
    Edit: 99.99.1
    cmake-tools-99.99.1.zip

    I tested it rudimentarily:

    1. Installed the extension manually, overwriting the latest release:
      grafik

    2. Made sure my code is really in the main.js of the extension now running (see "C:\Users\my_username.vscode\extensions\ms-vscode.cmake-tools-99.99.0\dist\main.js":
      grafik

    3. Tested it with just one warning (will test it extensively in the following weeks):
      grafik
      Undefined reference is detected successfully.

    I also updated the typescript playground code where I tested the regex stuff over the last couple of months (see here).

    So at first glance looking good, but since I am not proficient at all with typescript and desktop applications in general, I might have overlooked something. Looking forward to your feedback!

  19. gcampbell-msft commented on Aug 5, 2024

    @gcampbell-msft
    Collaborator

    0xemgy Thanks for all of your work! Yes, I agree that we should solve that bug and am happy for you to implement and continue testing,

  20. 0xemgy commented on Aug 25, 2024

    @0xemgy
    Contributor

    Garrett Campbell (@gcampbell-msft) I was able to test my changes extensively over the last 3 weeks at work. I also added a few unit tests and cleaned up the regex expressions. For my use cases it is working properly. It is commited in the PR 3950 and is ready for review.

    Of course, feedback of RolfNoot would be much appreciated.

  21. v-frankwang commented on Aug 29, 2024

    @v-frankwang

    Garrett Campbell (@gcampbell-msft) The user made some changes to the PR: #3950 based on the survey and asked you to review it.

  22. gcampbell-msft commented on Nov 5, 2024

    @gcampbell-msft
    Collaborator

    Fixed in #3950.

    Please open new issues if errors still remain. Thanks everyone and thanks to 0xemgy for their contribution!

  23. moved this from Pending Prioritization to Completed in CMake Toolson Nov 5, 2024
  24. Yingzi1234 commented on Feb 14, 2025

    @Yingzi1234

    RolfNoot We're in the process of verifying this issue, but we're not sure if the issue has been fixed, can you help us determine this by looking at the information below? If it's not correct, would you be able to provide us with a reproduction project?

    Repro steps:

    1. Download and unzip this folder CMAKE.zip
    2. Open it with VSCode and configure this folder
    3. Build this folder and check if the error info occurs on Problem window

    Actual result:
    Build failed but no error message occurs on Problem window
    Image

  25. 0xemgy commented on Mar 8, 2025

    @0xemgy
    Contributor

    v-cathyzhang (@Yingzi1234) I implemented the fix, so I hope it's ok if I just respond here.

    The error message provided by RolfNoot occurs in the Problem window after the fix.
    Its is /Volumes/Data/VScode/Gatewise_AddOn01/source/main.c:105: undefined reference to 'no_reference'.

    The message you get in the gif has a different format:
    C:/Users/v-cathyzhang/Desktop/CMAKE/main.cpp:4:(.text+0xe): undefined reference to 'someFunction()'.
    The difference is marked in bold. After the line number, you additionally get section and offset of the line.
    This format is currently not supported, so the message does not get parsed.

    Running your example zip, I get the message format without the section, which is correctly parsed:
    Image
    Image

    Since you are using mingw version 14.2.0, and I use 13.1.0, I assume the output format might have changed.

    Support for such formats could easily be added to the error parser if desired.

  26. 0xemgy commented on Mar 9, 2025

    @0xemgy
    Contributor

    Garrett Campbell (@gcampbell-msft), while looking into the issue v-cathyzhang (@Yingzi1234) mentioned, I ran into a couple of other things:

    1. Even after updating gcc to version 14.2.0, I don't get the linker error format with the extra section info.
    2. When I used Unix Makefiles as a generator, I found that my gnuld modifications caused false positive make errors. I only used Ninja before, and the unit test that was already there only checks for false positives with the gcc parser, not the gnuld parser, so I didn't run into this problem then.
    3. When I use Ninja as the generator again, the "undefined reference" error doesn't get parsed anymore, even without the extra section info. This is due to a trailing "\r". I'm not sure if this was the case before.
    4. After some more messing around, it turns out that another linker error, the one for "multiple definitions", is still detected, but parsed incorrectly now. It looks like the format has changed, or maybe I manually tested with the wrong format a few months ago and did not try to provoke the error with a build.

    I've got 2, 3, and 4 sorted in #4341.

    If we're going to fix 1, I'd probably need some settings to get those output formats with the extra section info. Otherwise, I could just assume the format seen in the GIF.

    Hope that works for now. How do you want to proceed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature: diagnosticsissues with problem matchers for compiler outputbuga bug in the producthelp wantedwe currently are not planning work on this and would like help from the open source community

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions