Skip to content

Commit

Permalink
Add 'extern' to all declarations to allow -fno-common option [v2]
Browse files Browse the repository at this point in the history
-fno-common requires there to be only one definition of each global
symbol, with other usages being 'extern' declarations. This provides
compatibility with GCC 10 where -fno-common is now the default.

Signed-off-by: Keith Packard <[email protected]>

---

v2:
	Fix code formatting
  • Loading branch information
keith-packard committed May 7, 2020
1 parent db4ba0f commit d60b910
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions metal_header/device.c++
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ std::string Device::platform_define_offset(node n, std::string suffix) {
* "__metal_" namespace */
void Device::emit_struct_decl(std::string type, const node &n) {
emit_comment(n);
os << "struct __metal_driver_" << type << " __metal_dt_" << n.handle()
<< ";\n\n";
os << "extern /* hello */ struct __metal_driver_" << type << " __metal_dt_"
<< n.handle() << ";\n\n";
}

void Device::emit_struct_decl(std::string type, std::string suffix,
const node &n) {
emit_comment(n);
os << "struct __metal_driver_" << type << "_" << suffix << " __metal_dt_"
<< n.handle() << "_" << suffix << ";\n\n";
os << "extern /* hello */ struct __metal_driver_" << type << "_" << suffix
<< " __metal_dt_" << n.handle() << "_" << suffix << ";\n\n";
}

void Device::emit_struct_begin(std::string type, const node &n) {
Expand Down
2 changes: 1 addition & 1 deletion metal_header/memory.c++
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void memory::include_headers() { os << "#include <metal/memory.h>\n"; }

void memory::declare_structs() {
auto declare = [&](node n) {
os << "struct metal_memory __metal_dt_mem_" << n.handle() << ";\n\n";
os << "extern struct metal_memory __metal_dt_mem_" << n.handle() << ";\n\n";
};

dtb.match(std::regex("sifive,sram0"), declare, std::regex("sifive,testram0"),
Expand Down
2 changes: 1 addition & 1 deletion metal_header/riscv_cpu_intc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ string riscv_cpu_intc::handle(node n) {

void riscv_cpu_intc::declare_structs() {
dtb.match(std::regex(compat_string), [&](node n) {
os << "struct __metal_driver_riscv_cpu_intc __metal_dt_" << handle(n)
os << "extern struct __metal_driver_riscv_cpu_intc __metal_dt_" << handle(n)
<< ";\n\n";
});
}
Expand Down
2 changes: 1 addition & 1 deletion metal_header/sifive_buserror0.c++
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void sifive_buserror0::define_inlines() {
void sifive_buserror0::declare_structs() {
dtb.match(std::regex(compat_string), [&](node n) {
emit_comment(n);
os << "struct metal_buserror"
os << "extern struct metal_buserror"
" __metal_dt_"
<< n.handle() << ";\n\n";
});
Expand Down
4 changes: 2 additions & 2 deletions metal_header/sifive_rtc0.c++
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ void sifive_rtc0::define_inlines() {
void sifive_rtc0::declare_structs() {
dtb.match(std::regex(compat_string), [&](node n) {
emit_comment(n);
os << "struct __metal_driver_sifive_rtc0 __metal_dt_rtc_" << n.instance()
<< ";\n\n";
os << "extern struct __metal_driver_sifive_rtc0 __metal_dt_rtc_"
<< n.instance() << ";\n\n";
});
}

Expand Down

0 comments on commit d60b910

Please sign in to comment.