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

Preemptable linkage #80

Open
philipc opened this issue May 7, 2019 · 5 comments
Open

Preemptable linkage #80

philipc opened this issue May 7, 2019 · 5 comments

Comments

@philipc
Copy link
Collaborator

philipc commented May 7, 2019

For defined symbols, faerie always references the section symbol in ELF relocations:

(to_shndx - 3) + self.special_symbols.len()

I think this means that these relocations can never be preempted. However, my understanding is that normally all global symbols are preemptable, regardless of whether they are weak.

e.g. for the following C code:

static int local() { return 1; }
int global() { return 1; }
__attribute__((weak)) int weak() { return 1; }

int bar(int x) {
	return local() + global() + weak();
}

I get these relocations (compiled with gcc -fPIC -ffunction-sections):

  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000012  000500000002 R_X86_64_PC32     0000000000000000 .text.local - 4
00000000001e  000d00000004 R_X86_64_PLT32    0000000000000000 global - 4
00000000002a  000e00000004 R_X86_64_PLT32    0000000000000000 weak - 4

To complicate this, cranelift has Linkage::Preemptible, but this is translated to weak for the faerie backend, which seems to be conflating weak and preemptable.

Is my understanding of all this correct?

cc @pchickey since I think you did the weak support?

@pchickey
Copy link
Collaborator

pchickey commented May 7, 2019

I don't follow the C code example. Is faerie not capable of emitting those relocations? How is the difference related to the symbol table?

I don't think I understand the distinction between preemptable and weak. My understanding was that @sunfishcode selected those variants because the two were synonyms.

@philipc
Copy link
Collaborator Author

philipc commented May 7, 2019

For the C code example, note that the global and weak relocations reference the symbol, not the section (e.g. global and not .text.global). faerie can't emit them because it always uses the section (and often using the section is right, such as for the local symbol).

For preemptable vs weak, maybe I am reading too much into the name. Have a look at https://llvm.org/docs/LangRef.html#runtime-preemption-specifiers. It would be good if @sunfishcode could clarify the intent here.

@pchickey
Copy link
Collaborator

pchickey commented May 7, 2019

Thanks, I missed the distinction between referencing a symbol and a section. I agree that this is something we should correct.

@sunfishcode
Copy link
Collaborator

@philipc I believe you are correct, and we should fix this.

@philipc
Copy link
Collaborator Author

philipc commented May 7, 2019

@sunfishcode Is cranelift's Linkage::Preemptible meant to be the same as weak, or do we need to add another variant for it?

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

No branches or pull requests

3 participants