compiler.h: add __weak macro

Instead of writing out '__attribute__((weak))' use a shorter form.

Change-Id: If418a1d55052780077febd2d8f2089021f414b91
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/25767
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Justin TerAvest <teravest@chromium.org>
diff --git a/src/lib/boot_device.c b/src/lib/boot_device.c
index e7968f4..c5afce7 100644
--- a/src/lib/boot_device.c
+++ b/src/lib/boot_device.c
@@ -14,8 +14,9 @@
  */
 
 #include <boot_device.h>
+#include <compiler.h>
 
-void __attribute__((weak)) boot_device_init(void)
+void __weak boot_device_init(void)
 {
 	/* Provide weak do-nothing init. */
 }
diff --git a/src/lib/bootblock.c b/src/lib/bootblock.c
index 2e228c6..bee2845 100644
--- a/src/lib/bootblock.c
+++ b/src/lib/bootblock.c
@@ -16,6 +16,7 @@
 
 #include <arch/exception.h>
 #include <bootblock_common.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <delay.h>
 #include <pc80/mc146818rtc.h>
@@ -25,10 +26,10 @@
 
 DECLARE_OPTIONAL_REGION(timestamp);
 
-__attribute__((weak)) void bootblock_mainboard_early_init(void) { /* no-op */ }
-__attribute__((weak)) void bootblock_soc_early_init(void) { /* do nothing */ }
-__attribute__((weak)) void bootblock_soc_init(void) { /* do nothing */ }
-__attribute__((weak)) void bootblock_mainboard_init(void) { /* do nothing */ }
+__weak void bootblock_mainboard_early_init(void) { /* no-op */ }
+__weak void bootblock_soc_early_init(void) { /* do nothing */ }
+__weak void bootblock_soc_init(void) { /* do nothing */ }
+__weak void bootblock_mainboard_init(void) { /* do nothing */ }
 
 asmlinkage void bootblock_main_with_timestamp(uint64_t base_timestamp)
 {
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index 9e81bd3..2dcd429 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -20,6 +20,7 @@
 #include <boot_device.h>
 #include <cbfs.h>
 #include <commonlib/compression.h>
+#include <compiler.h>
 #include <endian.h>
 #include <lib.h>
 #include <symbols.h>
@@ -308,7 +309,7 @@
 /* This struct is marked as weak to allow a particular platform to
  * override the master header logic. This implementation should work for most
  * devices. */
-const struct cbfs_locator __attribute__((weak)) cbfs_master_header_locator = {
+const struct cbfs_locator __weak cbfs_master_header_locator = {
 	.name = "Master Header Locator",
 	.locate = cbfs_master_header_props,
 };
diff --git a/src/lib/cbmem_common.c b/src/lib/cbmem_common.c
index 166ec87..2451fca 100644
--- a/src/lib/cbmem_common.c
+++ b/src/lib/cbmem_common.c
@@ -14,6 +14,7 @@
  */
 #include <console/console.h>
 #include <cbmem.h>
+#include <compiler.h>
 #include <bootstate.h>
 #include <rules.h>
 #include <symbols.h>
@@ -37,7 +38,7 @@
 	}
 }
 
-void __attribute__((weak)) cbmem_fail_resume(void)
+void __weak cbmem_fail_resume(void)
 {
 }
 
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index e786443..2970215 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -16,6 +16,7 @@
  */
 
 #include <arch/cbconfig.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <console/uart.h>
 #include <ip_checksum.h>
@@ -244,9 +245,9 @@
 #endif /* CONFIG_VBOOT */
 #endif /* CONFIG_CHROMEOS */
 
-__attribute__((weak)) uint32_t board_id(void) { return UNDEFINED_STRAPPING_ID; }
-__attribute__((weak)) uint32_t ram_code(void) { return UNDEFINED_STRAPPING_ID; }
-__attribute__((weak)) uint32_t sku_id(void) { return UNDEFINED_STRAPPING_ID; }
+__weak uint32_t board_id(void) { return UNDEFINED_STRAPPING_ID; }
+__weak uint32_t ram_code(void) { return UNDEFINED_STRAPPING_ID; }
+__weak uint32_t sku_id(void) { return UNDEFINED_STRAPPING_ID; }
 
 static void lb_board_id(struct lb_header *header)
 {
@@ -441,7 +442,7 @@
 	rec->timestamp = coreboot_version_timestamp;
 }
 
-void __attribute__((weak)) lb_board(struct lb_header *header) { /* NOOP */ }
+void __weak lb_board(struct lb_header *header) { /* NOOP */ }
 
 /*
  * It's possible that the system is using a SPI flash as the boot device,
@@ -449,7 +450,7 @@
  * case don't provide any information as the correct information is
  * not known.
  */
-void __attribute__((weak)) lb_spi_flash(struct lb_header *header) { /* NOOP */ }
+void __weak lb_spi_flash(struct lb_header *header) { /* NOOP */ }
 
 static struct lb_forward *lb_forward(struct lb_header *header,
 	struct lb_header *next_header)
diff --git a/src/lib/fallback_boot.c b/src/lib/fallback_boot.c
index 443f209..a079910 100644
--- a/src/lib/fallback_boot.c
+++ b/src/lib/fallback_boot.c
@@ -1,8 +1,9 @@
 #include <fallback.h>
+#include <compiler.h>
 #include <watchdog.h>
 
 /* Implement platform specific override. */
-void __attribute__((weak)) set_boot_successful(void) { }
+void __weak set_boot_successful(void) { }
 
 void boot_successful(void)
 {
diff --git a/src/lib/gpio.c b/src/lib/gpio.c
index 48db262..b52d7b0 100644
--- a/src/lib/gpio.c
+++ b/src/lib/gpio.c
@@ -15,6 +15,7 @@
 
 #include <assert.h>
 #include <base3.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <delay.h>
 #include <gpio.h>
@@ -168,13 +169,13 @@
 }
 
 /* Default handler for ACPI path is to return NULL */
-__attribute__((weak)) const char *gpio_acpi_path(gpio_t gpio)
+__weak const char *gpio_acpi_path(gpio_t gpio)
 {
 	return NULL;
 }
 
 /* Default handler returns 0 because type of gpio_t is unknown */
-__attribute__((weak)) uint16_t gpio_acpi_pin(gpio_t gpio)
+__weak uint16_t gpio_acpi_pin(gpio_t gpio)
 {
 	return 0;
 }
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index 0deab4b..6fd55d7 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -21,6 +21,7 @@
 #include <adainit.h>
 #include <arch/exception.h>
 #include <bootstate.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <console/post_codes.h>
 #include <cbmem.h>
@@ -115,7 +116,7 @@
 	BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
 };
 
-void __attribute__((weak)) arch_bootstate_coreboot_exit(void) { }
+void __weak arch_bootstate_coreboot_exit(void) { }
 
 static boot_state_t bs_pre_device(void *arg)
 {
diff --git a/src/lib/imd_cbmem.c b/src/lib/imd_cbmem.c
index 5713c2c..cc1294f 100644
--- a/src/lib/imd_cbmem.c
+++ b/src/lib/imd_cbmem.c
@@ -15,6 +15,7 @@
 
 #include <bootstate.h>
 #include <bootmem.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <cbmem.h>
 #include <imd.h>
@@ -109,7 +110,7 @@
 	cbmem_initialize_empty_id_size(0, 0);
 }
 
-void __attribute__((weak)) cbmem_top_init(void)
+void __weak cbmem_top_init(void)
 {
 }
 
diff --git a/src/lib/prog_loaders.c b/src/lib/prog_loaders.c
index 128869b..8a6d6af 100644
--- a/src/lib/prog_loaders.c
+++ b/src/lib/prog_loaders.c
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <cbfs.h>
 #include <cbmem.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <fallback.h>
 #include <halt.h>
@@ -71,9 +72,9 @@
 	halt();
 }
 
-void __attribute__((weak)) stage_cache_add(int stage_id,
+void __weak stage_cache_add(int stage_id,
 						const struct prog *stage) {}
-void __attribute__((weak)) stage_cache_load_stage(int stage_id,
+void __weak stage_cache_load_stage(int stage_id,
 							struct prog *stage) {}
 
 static void ramstage_cache_invalid(void)
@@ -164,7 +165,7 @@
 static struct prog global_payload =
 	PROG_INIT(PROG_PAYLOAD, CONFIG_CBFS_PREFIX "/payload");
 
-void __attribute__((weak)) mirror_payload(struct prog *payload)
+void __weak mirror_payload(struct prog *payload)
 {
 }
 
diff --git a/src/lib/prog_ops.c b/src/lib/prog_ops.c
index 44a32d1..5e670d3 100644
--- a/src/lib/prog_ops.c
+++ b/src/lib/prog_ops.c
@@ -14,6 +14,7 @@
  * GNU General Public License for more details.
  */
 
+#include <compiler.h>
 #include <program_loading.h>
 
 /* For each segment of a program loaded this function is called*/
@@ -23,13 +24,13 @@
 	arch_segment_loaded(start, size, flags);
 }
 
-void __attribute__((weak)) platform_segment_loaded(uintptr_t start,
+void __weak platform_segment_loaded(uintptr_t start,
 							size_t size, int flags)
 {
 	/* do nothing */
 }
 
-void __attribute__((weak)) arch_segment_loaded(uintptr_t start, size_t size,
+void __weak arch_segment_loaded(uintptr_t start, size_t size,
 						int flags)
 {
 	/* do nothing */
@@ -41,7 +42,7 @@
 	arch_prog_run(prog);
 }
 
-void __attribute__((weak)) platform_prog_run(struct prog *prog)
+void __weak platform_prog_run(struct prog *prog)
 {
 	/* do nothing */
 }
diff --git a/src/lib/reset.c b/src/lib/reset.c
index 703118a..2c95292 100644
--- a/src/lib/reset.c
+++ b/src/lib/reset.c
@@ -14,6 +14,7 @@
  */
 
 #include <arch/cache.h>
+#include <compiler.h>
 #include <console/console.h>
 #include <halt.h>
 #include <reset.h>
@@ -27,10 +28,10 @@
 }
 
 /* Not all platforms implement all reset types. Fall back to hard_reset. */
-__attribute__((weak)) void do_global_reset(void) { __hard_reset(); }
-__attribute__((weak)) void do_soft_reset(void) { __hard_reset(); }
+__weak void do_global_reset(void) { __hard_reset(); }
+__weak void do_soft_reset(void) { __hard_reset(); }
 
-__attribute__((weak)) void soc_reset_prepare(enum reset_type rt) { /* no-op */ }
+__weak void soc_reset_prepare(enum reset_type rt) { /* no-op */ }
 
 void global_reset(void)
 {
diff --git a/src/lib/timer.c b/src/lib/timer.c
index adc0d07..625bfc0 100644
--- a/src/lib/timer.c
+++ b/src/lib/timer.c
@@ -13,12 +13,13 @@
  * GNU General Public License for more details.
  */
 
+#include <compiler.h>
 #include <console/console.h>
 #include <timer.h>
 #include <delay.h>
 #include <thread.h>
 
-__attribute__((weak)) void init_timer(void) { /* do nothing */ }
+__weak void init_timer(void) { /* do nothing */ }
 
 void udelay(unsigned int usec)
 {
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index 2ab7253..bf49365 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -361,7 +361,7 @@
 RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
 
 /* Provide default timestamp implementation using monotonic timer. */
-uint64_t  __attribute__((weak)) timestamp_get(void)
+uint64_t  __weak timestamp_get(void)
 {
 	struct mono_time t1, t2;
 
@@ -375,7 +375,7 @@
 }
 
 /* Like timestamp_get() above this matches up with microsecond granularity. */
-int __attribute__((weak)) timestamp_tick_freq_mhz(void)
+int __weak timestamp_tick_freq_mhz(void)
 {
 	return 1;
 }
diff --git a/src/lib/wrdd.c b/src/lib/wrdd.c
index da082f8..a8390cf 100644
--- a/src/lib/wrdd.c
+++ b/src/lib/wrdd.c
@@ -14,9 +14,10 @@
  * GNU General Public License for more details.
  */
 
+#include <compiler.h>
 #include <wrdd.h>
 
-uint16_t __attribute__((weak)) wifi_regulatory_domain(void)
+uint16_t __weak wifi_regulatory_domain(void)
 {
 	return WRDD_DEFAULT_REGULATORY_DOMAIN;
 }