Skip to content

Pass -c when compiling SDL2 object files#9511

Merged
sbc100 merged 1 commit into
incomingfrom
fix_sdl2_build
Sep 26, 2019
Merged

Pass -c when compiling SDL2 object files#9511
sbc100 merged 1 commit into
incomingfrom
fix_sdl2_build

Conversation

@sbc100

@sbc100 sbc100 commented Sep 26, 2019

Copy link
Copy Markdown
Collaborator

Without -c emscripten will try to run lld on the object files its
given to produce another object file. We should probably disable that
for the single build case. This breakage was introduced in #9444 and
we should probably address it, but compiling without -c is also
broken so fixing here.

Fixes #9510

Without `-c` emscripten will try to run lld on the object files its
given to produce another object file.  We should probably disable that
for the single build case.  This breakage was introduced in #9444 and
we should probably address it, but compiling without `-c` is also
broken so fixing here.

Fixes #9510
@kripken

kripken commented Sep 26, 2019

Copy link
Copy Markdown
Member

Without -c emscripten will try to run lld on the object files its given to produce another object file.

That surprises me - I didn't realize that was happening when looking at the recent linking PRs. I think we should fix that directly, i.e., emcc a.c -o a.o does the same thing even if adding -c, as it always did.

I realize it's a little odd that emscripten looks at the suffix of the output file to know what to emit, and I'm open to finding a path to changing that, but we need to think carefully about how to do that without breaking users.

@kripken

kripken commented Sep 26, 2019

Copy link
Copy Markdown
Member

Alternatively, maybe we should make emcc a.c -o a.o error if it doesn't have -c provided? I think that would move things in the direction you want @sbc100 ? That would break people but at least a clear error would make it an easy fix probably.

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the linking regression fix this PR looks good.

@sbc100

sbc100 commented Sep 26, 2019

Copy link
Copy Markdown
Collaborator Author

Without -c emscripten will try to run lld on the object files its given to produce another object file.

That surprises me - I didn't realize that was happening when looking at the recent linking PRs. I think we should fix that directly, i.e., emcc a.c -o a.o does the same thing even if adding -c, as it always did.

I realize it's a little odd that emscripten looks at the suffix of the output file to know what to emit, and I'm open to finding a path to changing that, but we need to think carefully about how to do that without breaking users.

I agree and I will restore the behavior. Its a little more subtle than one might imagine though.

The old behaviour had a special case for a single object file:

emcc test1.c test2.c -o test.o -> Compile each source file then use lld to link them together into a bigger object file.

emcc test1.c -o test.o -> Compile the single source file then skip using lld since its already a single object and just copy it.

The new behaviour is that it run lld in all cases, even on a single object file. This means that if you pass certain flags such as -s RELOCATABLE you might get some very different behaviour.

The SDL build script was missing the -c but due to the previous "just copy it if its a single object" file this was completely ignored/harmless.

I'm happy to temporarily restore the previous behaviour.

However, in the long run I think we can do a bit better. I don't think either of the above use cases is useful or worth maintaining. There is a use case for linking object into a single object, but I think its rare and we should only allow it when all the input files are also objects. So passing a source file with output as an object file without -c would be a hard error.

@sbc100 sbc100 merged commit e6fd503 into incoming Sep 26, 2019
@sbc100 sbc100 deleted the fix_sdl2_build branch September 26, 2019 07:48
sbc100 added a commit that referenced this pull request Sep 30, 2019
Rather than run the linker, simply copy the object file to the
output.  This restores the previously behaviour.  In the future we
probably want to put this behavior behind a flag as link objects
together should be explicit.

See #9511
sbc100 added a commit that referenced this pull request Oct 8, 2019
Rather than run the linker, simply copy the object file to the
output.  This restores the previously behaviour.  In the future we
probably want to put this behavior behind a flag as link objects
together should be explicit.

See #9511
sbc100 added a commit that referenced this pull request Oct 8, 2019
Rather than run the linker, simply copy the object file to the
output.  This restores the previously behaviour.  In the future we
probably want to put this behavior behind a flag as link objects
together should be explicit.

See: #9511
Fixes: #9571
sbc100 added a commit that referenced this pull request Oct 8, 2019
Rather than run the linker, simply copy the object file to the
output.  This restores the previously behaviour.  In the future we
probably want to put this behavior behind a flag as link objects
together should be explicit.

See: #9511
Fixes: #9571
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
Without `-c` emscripten will try to run lld on the object files its
given to produce another object file.  We should probably disable that
for the single build case.  This breakage was introduced in emscripten-core#9444 and
we should probably address it, but compiling without `-c` is also
broken so fixing here.

Fixes emscripten-core#9510
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
…core#9548)

Rather than run the linker, simply copy the object file to the
output.  This restores the previously behaviour.  In the future we
probably want to put this behavior behind a flag as link objects
together should be explicit.

See: emscripten-core#9511
Fixes: emscripten-core#9571
iamahuman added a commit to iamahuman/emscripten that referenced this pull request Jan 20, 2021


Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see emscripten-core#9510 and emscripten-core#9571).

However, emscripten-core#9510 was addressed by emscripten-core#9511, and emscripten-core#9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
iamahuman added a commit to iamahuman/emscripten that referenced this pull request Jan 20, 2021


Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see emscripten-core#9510 and emscripten-core#9571).

However, emscripten-core#9510 was addressed by emscripten-core#9511, and emscripten-core#9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
iamahuman added a commit to iamahuman/emscripten that referenced this pull request Jan 21, 2021


Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see emscripten-core#9510 and emscripten-core#9571).

However, emscripten-core#9510 was addressed by emscripten-core#9511, and emscripten-core#9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
iamahuman added a commit to iamahuman/emscripten that referenced this pull request Jan 21, 2021


Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see emscripten-core#9510 and emscripten-core#9571).

However, emscripten-core#9510 was addressed by emscripten-core#9511, and emscripten-core#9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
iamahuman added a commit to iamahuman/emscripten that referenced this pull request Jan 21, 2021


Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see emscripten-core#9510 and emscripten-core#9571).

However, emscripten-core#9510 was addressed by emscripten-core#9511, and emscripten-core#9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
sbc100 pushed a commit that referenced this pull request Jan 21, 2021
Remove the optimization (again) for the special case of single object
input, which skips the linker and directly copies the input object file
to output.

This behavior interferes with linking (merging) all objects in a
library archive into a single object, done with the following command:

    cc -o lib.o -r -Wl,--whole-archive lib.a

The optimization was once useful when no clear distinction was made
between compile mode and link-only mode.  It was also required for
compatibility (see #9510 and #9571).

However, #9510 was addressed by #9511, and #9600 introduced the '-r'
flag that allows to explicitly indicate linking to an object, making the
optimization less useful.
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 this pull request may close these issues.

1.38.46-upstream regression on sdl2 build

3 participants