[PATCH] D137360: [Linker] Remove nocallback attribute while linking

Gulfem Savrun Yeniceri via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 12:27:29 PST 2022


gulfem marked 3 inline comments as done.
gulfem added inline comments.


================
Comment at: llvm/lib/Linker/IRMover.cpp:1536
+/// nocallback attribute might call an imported function. When it's caller
+/// module and important function's module are linked together, the function
+/// with nocallback attribute now jumps back into its caller's module.
----------------
tejohnson wrote:
> Should "important" be "imported"?
> 
> Also, I'm not completely following the situation described in these sentences. Can you give me a more detailed example? I might be able to suggest clearer wording once I understand better.
This is the great example that @mysterymath came up with to explain the problem in the bug reported to `gcc` (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106725)
```
==> ext.c <==
void set_value(int v);

void external_call(void) {
  set_value(0);
}

==> lto.c <==
static int value;
void set_value(int v) { value = v; }
int get_value(void) { return value; }

==> main.c <==
#include <stdio.h>

void set_value(int v);
int get_value(void);
__attribute__((leaf)) void external_call(void);

int main(void) {
  set_value(42);
  external_call();
  printf("%d\n", get_value());
}
```

This is the scenario that I was trying to summarize here, where a function with `nocallback` attribute returns to its caller's module other than a `return` or an `exception`. `external_call()` is the function that has the `leaf` attribute, and `main()` is its caller. Normally, `external_call()` returns to its caller's module via a `return`. When `lto.c` and `main.c` are linked together, `external_call()` calls an imported function(`set_value()`), which is now in the same module with its caller. So, it returned to its caller's module via a function call, not with a return or an exception.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137360/new/

https://reviews.llvm.org/D137360



More information about the llvm-commits mailing list