Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still builds successfully when defining duplicate functions (IDFGH-12819) #13793

Closed
3 tasks done
ElectricThanhTung opened this issue May 14, 2024 · 4 comments
Closed
3 tasks done
Assignees
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@ElectricThanhTung
Copy link

ElectricThanhTung commented May 14, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.2.1

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

What is the expected behavior?

Build fail

What is the actual behavior?

Sitll build success

Steps to reproduce.

  1. Define 2 functions (non-static function) with the same name but in 2 different source files
  2. Call that function in app_main
  3. Build source code
    image

Build or installation Logs.

No response

More Information.

Project reproduces the issue:
sample_project.zip

@ElectricThanhTung ElectricThanhTung added the Type: Bug bugs in IDF label May 14, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 14, 2024
@github-actions github-actions bot changed the title Still builds successfully when defining duplicate functions Still builds successfully when defining duplicate functions (IDFGH-12819) May 14, 2024
@KaeLL
Copy link
Contributor

KaeLL commented May 14, 2024

Here's one better: building your sample_project on release/4.4 triggers an infinite loop in the build process.

@igrr
Copy link
Member

igrr commented May 14, 2024

The original issue reported by @ElectricThanhTung is explained by the fact that once the linker finds the function Test in one of the object files, it has no reason to consider the other object file for linking, as it doesn't resolve any of the unresolved references. This is the behavior of GNU linker for object files inside static libraries.

If both source files contained symbols required to resolve undefined references, then the linker would try to include both object files into the output file, resulting in the duplicate symbol error.

The duplicate symbol error would also be observed if both object files were linked into the executable directly, without first creating a static library.

(This article explains the linker logic very well, I think, and is really worth reading!)

@igrr
Copy link
Member

igrr commented May 14, 2024

Here's one better: building your sample_project on release/4.4 triggers an infinite loop in the build process.

@KaeLL Zip files contain local modification time, and the archive was created in a timezone which is to the east of you. So when you extract the archive, the modification time of main/CMakeLists.txt is in the future, relative to your local time (even though creation time is the current time). This causes Ninja to re-run CMake. You can verify this (for another hour or so) if you run cmake --build build -- -d explain:

ninja explain: output build.ninja older than most recent input ../main/CMakeLists.txt (1715720472247114987 vs 1715722574000000000)

— this shows the file which causes Ninja to re-run CMake.

I think this issue was fixed in Ninja or in CMake at some point. If you build with ninja >= 1.11, you should not meet this issue.

@KaeLL
Copy link
Contributor

KaeLL commented May 14, 2024

That's a really cool bug. And btw, I'm running ninja 1.11.1

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

5 participants