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

Two source files with same name, different extension generate same object file name #1294

Closed
Noxime opened this issue Nov 18, 2024 · 7 comments · Fixed by #1295
Closed

Two source files with same name, different extension generate same object file name #1294

Noxime opened this issue Nov 18, 2024 · 7 comments · Fixed by #1295

Comments

@Noxime
Copy link

Noxime commented Nov 18, 2024

Hi,

When building a project that has 2 sibling files with same name but different extension, they both result in the same filename for the object file. In my case:

...
.file("rv003usb.c")
.file("rv003usb.S")

produces two rv003usb.o files, with the latter overwriting the former. Thus, the resulting build either fails or is missing some symbols. I traced this to this line:

let obj = dst
.join(format!("{:016x}-{}", hasher.finish(), basename))
.with_extension("o");

@madsmtm
Copy link
Collaborator

madsmtm commented Nov 18, 2024

Yeah that's problematic. We could solve this two ways:

  1. Add the extension to the hash.
  2. Rewrite the whole thing to instead keep a HashMap<OsString, NonZero<u32>> for the compilation session, with each output file bumping a number in there.

@madsmtm
Copy link
Collaborator

madsmtm commented Nov 18, 2024

@NobodyXu do you know why we're even invoking the compiler for each source file? As far as I know, C compilers support building multiple files and linking them together in one step?

(Of course if we did #545 we'd have to do something else)

@NobodyXu
Copy link
Collaborator

I think adding extension to the hash is the right solution.

do you know why we're even invoking the compiler for each source file

Primary reason is for parallel compilation.

Also some people depends on it (extract the file from archive or uses compile_intermediate)

@madsmtm
Copy link
Collaborator

madsmtm commented Nov 19, 2024

Primary reason is for parallel compilation.

Doesn't Clang/GCC handle this internally themselves?

I just mean, having one process that loads and shares all the header files has bound to be faster than 10 processes doing that?

@NobodyXu
Copy link
Collaborator

Doesn't Clang/GCC handle this internally themselves?

No, AFAIK clang/gcc is single-thread.

I just mean, having one process that loads and shares all the header files has bound to be faster than 10 processes doing that?

Well that depends, if a header is large enough and reused multiple times, pre-compiling it to gcc/clang internal format would speed that up (and is supported).

In cc-rs, we compile the source files in parallel (.c/.cxx/.S), in the same way how Makefile would usually compile them in parallel.

@madsmtm
Copy link
Collaborator

madsmtm commented Nov 20, 2024

Doesn't Clang/GCC handle this internally themselves?

No, AFAIK clang/gcc is single-thread.

I just mean, having one process that loads and shares all the header files has bound to be faster than 10 processes doing that?

Well that depends, if a header is large enough and reused multiple times, pre-compiling it to gcc/clang internal format would speed that up (and is supported).

In cc-rs, we compile the source files in parallel (.c/.cxx/.S), in the same way how Makefile would usually compile them in parallel.

Ah, okay, thanks for the explanation!

@NobodyXu
Copy link
Collaborator

NobodyXu commented Nov 20, 2024

No worries.

BTW rustc is also designed in the same way originally, but recently rustc adds in multithreading to speedup compilation since the compile unit in rust is crate, whilst in c/c++ it's file.

The c/c++ model actually scales better despite it creates multiple processes (would be great if they can do multithreading), but with C++ module things are getting more complex.

https://stackoverflow.com/questions/33307657/how-do-i-use-c-modules-in-clang

and c++ module might be more expensive to compile as well

https://www.reddit.com/r/cpp/s/wLcdeTUndc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants