Skip to content

Commit 8916906

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#2008 from tautschnig/section-bug
[SV-COMP'18 19/19] Fixing "identifier XYZ not found" error.
2 parents 714ccff + 2a45e61 commit 8916906

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,16 +708,31 @@ 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

715720
if(full_spec.section.empty())
716721
apply_asm_label(full_spec.asm_label, symbol);
717722
else
718723
{
719-
std::string asm_name;
720-
asm_name=id2string(full_spec.section)+"$$";
724+
// section name is not empty, do a bit of parsing
725+
std::string asm_name = id2string(full_spec.section);
726+
if(asm_name[0] != '.')
727+
{
728+
warning().source_location = symbol.location;
729+
warning() << "section name `" << asm_name
730+
<< "' expected to start with `.'" << eom;
731+
}
732+
std::string::size_type primary_section = asm_name.find('.', 1);
733+
if(primary_section != std::string::npos)
734+
asm_name.resize(primary_section);
735+
asm_name += "$$";
721736
if(!full_spec.asm_label.empty())
722737
asm_name+=id2string(full_spec.asm_label);
723738
else

src/ansi-c/expr2c.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "expr2c.h"
1010

11+
#include <algorithm>
1112
#include <cassert>
1213
#include <cctype>
1314
#include <cstdio>
@@ -89,6 +90,9 @@ static std::string clean_identifier(const irep_idt &id)
8990
*it2='_';
9091
}
9192

93+
// rewrite . as used in ELF section names
94+
std::replace(dest.begin(), dest.end(), '.', '_');
95+
9296
return dest;
9397
}
9498

0 commit comments

Comments
 (0)