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

Clang should never emit zero-length functions if they may be address-taken #32380

Open
pcc opened this issue May 15, 2017 · 4 comments · May be fixed by #109732
Open

Clang should never emit zero-length functions if they may be address-taken #32380

pcc opened this issue May 15, 2017 · 4 comments · May be fixed by #109732
Labels
bugzilla Issues migrated from bugzilla clang:codegen confirmed Verified by a second party

Comments

@pcc
Copy link
Contributor

pcc commented May 15, 2017

Bugzilla Link 33033
Version unspecified
OS Linux
CC @zmodem,@zygoloid

Extended Description

If the linker places a zero-length function at the same address as another function, function pointer equality may be broken.

$ cat addr-taken.c

#include <stdio.h>
void f1() { __builtin_unreachable(); }
void f2() { __builtin_unreachable(); }
int main() {
  printf("%p %p\n", &f1, &f2);
}

$ clang -Os addr-taken.c
$ ./a.out
0x400510 0x400510

@zmodem
Copy link
Collaborator

zmodem commented Aug 8, 2017

We ran into a related problem with duplicate function entries in the CFG tables on Windows, see r301040. Perhaps we should enable that code always?

@pcc
Copy link
Contributor Author

pcc commented Aug 8, 2017

Sounds reasonable to me. We could avoid emitting the noop in functions with the unnamed_addr attribute, but it doesn't seem worth it to me.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Endilll
Copy link
Contributor

Endilll commented Sep 12, 2023

Still reproduces as of post-17 trunk: https://godbolt.org/z/Gj8x7oj1M

@Endilll Endilll added the confirmed Verified by a second party label Sep 12, 2023
@shafik
Copy link
Collaborator

shafik commented Sep 12, 2023

This feels related to: #48943

Worth noting gcc does the same opt: https://godbolt.org/z/MazzcYb1T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen confirmed Verified by a second party
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants