Skip to content

Commit e133964

Browse files
committed
C front-end: Section/ASM renaming also needs to be applied to aliases
The example taken from the Linux kernel shows that people mix weak aliases with section attributes. Not updating the alias name results in a namespace lookup failure. gcc_attributes11 is a reduced example taken from SV-COMP, where the same problem arises.
1 parent 3e2ab6f commit e133964

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifdef __GNUC__
2+
// example extracted from SV-COMP's ldv-linux-3.4-simple/
3+
// 32_7_cpp_false-unreach-call_single_drivers-net-phy-dp83640
4+
static int __attribute__((__section__(".init.text")))
5+
__attribute__((no_instrument_function)) dp83640_init(void)
6+
{
7+
return 0;
8+
}
9+
int init_module(void) __attribute__((alias("dp83640_init")));
10+
#endif
11+
12+
int main()
13+
{
14+
#ifdef __GNUC__
15+
dp83640_init();
16+
#endif
17+
return 0;
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/ansi-c/gcc_attributes9/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ const char* __attribute__((section("s"))) __attribute__((weak)) bar();
1111
volatile int __attribute__((__section__(".init.data1"))) txt_heap_base1;
1212
volatile int __attribute__((__section__(".init.data3"))) txt_heap_base, __attribute__((__section__(".init.data4"))) txt_heap_size;
1313

14+
int __attribute__((__section__(".init.text"))) __attribute__((__cold__))
15+
__alloc_bootmem_huge_page(void *h);
16+
int __attribute__((__section__(".init.text"))) __attribute__((__cold__))
17+
alloc_bootmem_huge_page(void *h);
18+
int alloc_bootmem_huge_page(void *h)
19+
__attribute__((weak, alias("__alloc_bootmem_huge_page")));
20+
int __alloc_bootmem_huge_page(void *h)
21+
{
22+
return 1;
23+
}
1424
#endif
1525

1626
int main()
1727
{
1828
#ifdef __GNUC__
29+
int r = alloc_bootmem_huge_page(0);
30+
1931
static int __attribute__((section(".data.unlikely"))) __warned;
2032
__warned=1;
2133
return __warned;

src/ansi-c/c_typecheck_base.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,12 @@ void c_typecheck_baset::typecheck_declaration(
708708

709709
// alias function need not have been declared yet, thus
710710
// can't lookup
711-
symbol.value=symbol_exprt(full_spec.alias);
711+
// also cater for renaming/placement in sections
712+
const auto &renaming_entry = asm_label_map.find(full_spec.alias);
713+
if(renaming_entry == asm_label_map.end())
714+
symbol.value = symbol_exprt(full_spec.alias);
715+
else
716+
symbol.value = symbol_exprt(renaming_entry->second);
712717
symbol.is_macro=true;
713718
}
714719

0 commit comments

Comments
 (0)