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

"foo:" and "foo = ." produce different relocations on MachO #25755

Closed
llvmbot opened this issue Nov 2, 2015 · 8 comments
Closed

"foo:" and "foo = ." produce different relocations on MachO #25755

llvmbot opened this issue Nov 2, 2015 · 8 comments
Labels
bugzilla Issues migrated from bugzilla mc Machine (object) code

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 2, 2015

Bugzilla Link 25381
Resolution FIXED
Resolved on Mar 14, 2016 23:21
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @atamazov,@lhames

Extended Description

Given

.globl	_f

_f:
retq
.globl _g
_g:
callq _f
retq
.subsections_via_symbols

llvm-mc notices the two atoms and produces a relocation. Replace "_g:" with "_g = ." and we get none.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 3, 2015

Why is that a bug? "_g = ....." basically sets up an alias, but doesn't start a new atom.

The pre-llvm assembler behaves the same way, FWIW.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 3, 2015

It means that the linker (and anything else looking at .o files) will have a different idea from the assembler of what the atoms are.

@lhames
Copy link
Contributor

lhames commented Mar 7, 2016

As with #19577 , this matches the cctools as behavior.

My best

@lhames
Copy link
Contributor

lhames commented Mar 8, 2016

Oops. Comment cut off...

My best read of the current semantics matches what Jim said: cctools as (and consequently llvm-mc for MachO) treats named expressions as a separate namespace from regular symbols. That's different from GNU as's view of the world, where regular label definitions can be thought of as sugar for ' = .'.

(Note: This still doesn't fully explain #19577 , but that is another instance where labels and 'aliases' behave differently)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 8, 2016

Oops. Comment cut off...

My best read of the current semantics matches what Jim said: cctools as (and
consequently llvm-mc for MachO) treats named expressions as a separate
namespace from regular symbols. That's different from GNU as's view of the
world, where regular label definitions can be thought of as sugar for
' = .'.

That is fine, except that the linker has no idea if one wrote "a:" or "a = .", so the linker and the assembler disagree on what the atoms are.

Now, one way to solve this would be generate SF_AltEntry for "a = ." so that both the linker and assembler would agree that a is not defining an atom.

@lhames
Copy link
Contributor

lhames commented Mar 8, 2016

Oh god - I missed that this was emitting a symbol for _g when it's defined via "_g = .".

Yeah - that's horribly broken when mixed with .subsections_via_symbols. I can use ld -r and an order file to trick _g into calling a different function, without explicitly moving it around.

Given how unsafe it is, I wonder how often '=' is used? Maybe we can warn on it, at least if the RHS contains a symbol.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 8, 2016

Oh god - I missed that this was emitting a symbol for _g when it's defined
via "_g = .".

Yeah - that's horribly broken when mixed with .subsections_via_symbols. I
can use ld -r and an order file to trick _g into calling a different
function, without explicitly moving it around.

Given how unsafe it is, I wonder how often '=' is used? Maybe we can warn on
it, at least if the RHS contains a symbol.

Probably not too often, which is why I suggested fixing this by just letting the linker know that _g is not defining an atom.

@lhames
Copy link
Contributor

lhames commented Mar 15, 2016

Fixed in r263521 + r263528.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla mc Machine (object) code
Projects
None yet
Development

No branches or pull requests

2 participants