diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l
index e383b59d3d0d40f64d7432585e508a0f347f8dfd..1c2522a2398463710ff2a1759e57be87e8d60ad4 100644
--- a/contrib/cube/cubescan.l
+++ b/contrib/cube/cubescan.l
@@ -60,7 +60,7 @@ float        ({integer}|{real})([eE]{integer})?
 
 %%
 
-void __attribute__((noreturn))
+void pg_attribute_noreturn
 yyerror(NDBOX **result, const char *message)
 {
 	if (*yytext == YY_END_OF_BUFFER_CHAR)
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
index 19d59f523740124bcff3be5715d0259ff831d601..9b873adbc089793c4e64989959c6072435fa9595 100644
--- a/contrib/pg_upgrade/pg_upgrade.h
+++ b/contrib/pg_upgrade/pg_upgrade.h
@@ -359,7 +359,7 @@ void		optionally_create_toast_tables(void);
 bool
 exec_prog(const char *log_file, const char *opt_log_file,
 		  bool throw_error, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 4, 5)));
+pg_attribute_printf(4, 5);
 void		verify_directories(void);
 bool		pid_lock_file_exists(const char *datadir);
 
@@ -445,7 +445,7 @@ void		init_tablespaces(void);
 PGconn	   *connectToServer(ClusterInfo *cluster, const char *db_name);
 PGresult *
 executeQueryOrDie(PGconn *conn, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 char	   *cluster_conn_opts(ClusterInfo *cluster);
 
@@ -462,17 +462,17 @@ int			get_user_info(char **user_name_p);
 void		check_ok(void);
 void
 report_status(eLogType type, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 void
 pg_log(eLogType type, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 void
 pg_fatal(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2), noreturn));
+pg_attribute_printf(1, 2) pg_attribute_noreturn;
 void		end_progress_output(void);
 void
 prep_status(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 void		check_ok(void);
 const char *getErrorText(int errNum);
 unsigned int str2uint(const char *str);
@@ -489,7 +489,7 @@ void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
 void
 parallel_exec_prog(const char *log_file, const char *opt_log_file,
 				   const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+pg_attribute_printf(3, 4);
 void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
 							  char *old_pgdata, char *new_pgdata,
 							  char *old_tablespace);
diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c
index ec18526d96ef5956358da1b01926d285bc454127..ce17aa0d47669329aec449cfd5b0c66df1270467 100644
--- a/contrib/pg_upgrade/util.c
+++ b/contrib/pg_upgrade/util.c
@@ -82,7 +82,7 @@ prep_status(const char *fmt,...)
 
 
 static
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)))
+pg_attribute_printf(2, 0)
 void
 pg_log_v(eLogType type, const char *fmt, va_list ap)
 {
diff --git a/contrib/pg_xlogdump/pg_xlogdump.c b/contrib/pg_xlogdump/pg_xlogdump.c
index c471267fde74ded0dfa8406a4571a3842fd4dc66..15805be294033d6b32b6dd442b67806bd02659d7 100644
--- a/contrib/pg_xlogdump/pg_xlogdump.c
+++ b/contrib/pg_xlogdump/pg_xlogdump.c
@@ -69,7 +69,7 @@ typedef struct XLogDumpStats
 
 static void
 fatal_error(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 /*
  * Big red button to push when things go horribly wrong.
diff --git a/contrib/pgcrypto/px.h b/contrib/pgcrypto/px.h
index a01a58e29c0b3604fd7ea3b3e36807bdccab0f7e..297747c60a36035808abc4d7a7fc7d9abb75d657 100644
--- a/contrib/pgcrypto/px.h
+++ b/contrib/pgcrypto/px.h
@@ -208,7 +208,7 @@ void		px_memset(void *ptr, int c, size_t len);
 #ifdef PX_DEBUG
 void
 px_debug(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 #else
 #define px_debug(...)
 #endif
diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l
index a3e685488a80706b80ca0a0d17df7b1a7393593d..5fe4a2c45378ec9ca4a258c58d359b0de8c124eb 100644
--- a/contrib/seg/segscan.l
+++ b/contrib/seg/segscan.l
@@ -59,7 +59,7 @@ float        ({integer}|{real})([eE]{integer})?
 
 %%
 
-void __attribute__((noreturn))
+void pg_attribute_noreturn
 yyerror(SEG *result, const char *message)
 {
 	if (*yytext == YY_END_OF_BUFFER_CHAR)
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index fb4a2ddfcf0314c5da8dba99d819d9fafb020d5d..4a51defc529fb9e6fa0f22cd9d7cc024b626f17c 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -36,7 +36,7 @@ static void
 report_invalid_record(XLogReaderState *state, const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 static void ResetDecoder(XLogReaderState *state);
 
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 77158c1e8f013d2b405dca94760898170f8ed465..ee556f3600d8016b4e0763104367ac96c34870b4 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -286,8 +286,8 @@ int			AutovacuumLauncherPid = 0;
 static pid_t avlauncher_forkexec(void);
 static pid_t avworker_forkexec(void);
 #endif
-NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) __attribute__((noreturn));
-NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) __attribute__((noreturn));
+NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn;
+NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn;
 
 static Oid	do_start_worker(void);
 static void launcher_determine_sleep(bool canlaunch, bool recursing,
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 9b689af9156ece694442f0d3b52d5e35b228d0f7..800ae9362f8532ee328c2b87e8fdae8a67218909 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -86,7 +86,7 @@ static volatile sig_atomic_t ready_to_stop = false;
 static pid_t pgarch_forkexec(void);
 #endif
 
-NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) __attribute__((noreturn));
+NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn;
 static void pgarch_exit(SIGNAL_ARGS);
 static void ArchSigHupHandler(SIGNAL_ARGS);
 static void ArchSigTermHandler(SIGNAL_ARGS);
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 1148e29090d113ffc64dd52cafe1dd3297160fe7..abdfe8947a9460bec59b2325ef7643a6a3ffbf4e 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -251,7 +251,7 @@ static instr_time total_func_time;
 static pid_t pgstat_forkexec(void);
 #endif
 
-NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) __attribute__((noreturn));
+NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn;
 static void pgstat_exit(SIGNAL_ARGS);
 static void pgstat_beshutdown_hook(int code, Datum arg);
 static void pgstat_sighup_handler(SIGNAL_ARGS);
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index ac431e5dd5a64b7f19067e72cc8acd00040c1464..9b2e7f310c9bb42f639c9d47e55028a4b538ce94 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -380,8 +380,8 @@ static void LogChildExit(int lev, const char *procname,
 			 int pid, int exitstatus);
 static void PostmasterStateMachine(void);
 static void BackendInitialize(Port *port);
-static void BackendRun(Port *port) __attribute__((noreturn));
-static void ExitPostmaster(int status) __attribute__((noreturn));
+static void BackendRun(Port *port) pg_attribute_noreturn;
+static void ExitPostmaster(int status) pg_attribute_noreturn;
 static int	ServerLoop(void);
 static int	BackendStartup(Port *port);
 static int	ProcessStartupPacket(Port *port, bool SSLdone);
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 14ff1477c163484fbdb71f0d00e359903c440938..a27401f37005d509d356642c7f17f2678d798d69 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -130,7 +130,7 @@ static volatile sig_atomic_t rotation_requested = false;
 static pid_t syslogger_forkexec(void);
 static void syslogger_parseArgs(int argc, char *argv[]);
 #endif
-NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) __attribute__((noreturn));
+NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn;
 static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
 static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
 static void open_csvlogfile(void);
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index 449c127e1889e64602ef47c1168da640fde71b97..9abe47584291d3f52742f672795430282b5bb465 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -205,7 +205,7 @@ addlitchar(unsigned char ychar)
 	appendStringInfoChar(&litbuf, ychar);
 }
 
-void __attribute__((noreturn))
+void pg_attribute_noreturn
 yyerror(const char *message)
 {
 	ereport(ERROR,
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index af5c1cc3ba275b2a2cd7f3fa9b4def40b0ef3551..295611913aa960c3a75fd43ab20ec236fc900d5e 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -193,7 +193,7 @@ typedef void (*WalSndSendDataCallback) (void);
 static void WalSndLoop(WalSndSendDataCallback send_data);
 static void InitWalSenderSlot(void);
 static void WalSndKill(int code, Datum arg);
-static void WalSndShutdown(void) __attribute__((noreturn));
+static void WalSndShutdown(void) pg_attribute_noreturn;
 static void XLogSendPhysical(void);
 static void XLogSendLogical(void);
 static void WalSndDone(WalSndSendDataCallback send_data);
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 4e0cc30f1cc1ac77a1d03056fb9ad48e88a57627..b952c7c98ed54635e60abb6ba37a76772dbe54be 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -86,7 +86,7 @@ static const char *
 err_gettext(const char *str)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format_arg(1)));
+pg_attribute_format_arg(1);
 static void set_errdata_field(MemoryContextData *cxt, char **ptr, const char *str);
 
 /* Global variables */
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 0da1981e386924e35d3397a8f8c1b1370815cb82..6eaab4352aa53febf7b813bdc12af2c5b1b08951 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -132,7 +132,7 @@ char	   *GUC_check_errhint_string;
 static void
 do_serialize(char **destptr, Size *maxbytes, const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+pg_attribute_printf(3, 4);
 
 static void set_config_sourcefile(const char *name, char *sourcefile,
 					  int sourceline);
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 789fe8f25a14f0dcbc1935c4e229d295cfc41b2c..052caffe8db8691aa5848600653d6721e0802e7b 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -120,7 +120,7 @@ static void
 write_stderr(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 static void do_advice(void);
 static void do_help(void);
 static void set_mode(char *modeopt);
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index 1bf76114c09159cb91412fb5f593cf8a8f7c28c1..f58f96b06363c5d31604518c36c002f85233f4b4 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -81,7 +81,7 @@ static ParallelSlot *GetMyPSlot(ParallelState *pstate);
 static void
 parallel_msg_master(ParallelSlot *slot, const char *modulename,
 					const char *fmt, va_list ap)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
+pg_attribute_printf(3, 0);
 static void archive_close_connection(int code, void *arg);
 static void ShutdownWorkersHard(ParallelState *pstate);
 static void WaitForTerminatingWorkers(ParallelState *pstate);
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index a936ff81b9d900b2601003bef6390d077bedd02b..d484236c4fe350b0b3833ba8b224c1c17c6f412e 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -280,7 +280,7 @@ extern void archputs(const char *s, Archive *AH);
 extern int
 archprintf(Archive *AH, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 #define appendStringLiteralAH(buf,str,AH) \
 	appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index 144027ce974ef31a3fbaac37ce2ae9d00c3b1207..620ada53f1391b0cba76d38b8fe43e18c54b5bb7 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -378,7 +378,7 @@ struct _tocEntry
 extern int	parallel_restore(struct ParallelArgs *args);
 extern void on_exit_close_archive(Archive *AHX);
 
-extern void warn_or_exit_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+extern void warn_or_exit_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) pg_attribute_printf(3, 4);
 
 extern void WriteTOC(ArchiveHandle *AH);
 extern void ReadTOC(ArchiveHandle *AH);
@@ -429,8 +429,8 @@ extern int	ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *
 extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
 
 void		ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
-int			ahprintf(ArchiveHandle *AH, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+int			ahprintf(ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2, 3);
 
-void		ahlog(ArchiveHandle *AH, int level, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+void		ahlog(ArchiveHandle *AH, int level, const char *fmt,...) pg_attribute_printf(3, 4);
 
 #endif
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index f48d3696b393c2c9faa33c0473d86b315b5f5e3c..309b4b53dbc0546c8f4a55cba85324b3d3d7fd84 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -115,7 +115,7 @@ static void tarClose(ArchiveHandle *AH, TAR_MEMBER *TH);
 #ifdef __NOT_USED__
 static char *tarGets(char *buf, size_t len, TAR_MEMBER *th);
 #endif
-static int	tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+static int	tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...) pg_attribute_printf(3, 4);
 
 static void _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th);
 static TAR_MEMBER *_tarPositionTo(ArchiveHandle *AH, const char *filename);
diff --git a/src/bin/pg_dump/pg_backup_utils.h b/src/bin/pg_dump/pg_backup_utils.h
index 1bcc1a784fae757dad540fd41d52d6362de5e30b..2e9a69a615dbd2aea41b11a64d459104903c2ed4 100644
--- a/src/bin/pg_dump/pg_backup_utils.h
+++ b/src/bin/pg_dump/pg_backup_utils.h
@@ -30,15 +30,15 @@ extern const char *progname;
 extern void set_dump_section(const char *arg, int *dumpSections);
 extern void
 write_msg(const char *modulename, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 extern void
 vwrite_msg(const char *modulename, const char *fmt, va_list ap)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
+pg_attribute_printf(2, 0);
 extern void on_exit_nicely(on_exit_nicely_callback function, void *arg);
-extern void exit_nicely(int code) __attribute__((noreturn));
+extern void exit_nicely(int code) pg_attribute_noreturn;
 
 extern void
 exit_horribly(const char *modulename, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
+pg_attribute_printf(2, 3) pg_attribute_noreturn;
 
 #endif   /* PG_BACKUP_UTILS_H */
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index eb14d1cd465f7d0a1cb86f854cbfd2ee2cafdb3f..54266c1cb149cb37e4dfc0f830859871c91bafde 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -21,7 +21,7 @@ extern bool setQFout(const char *fname);
 extern void
 psql_error(const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern void NoticeProcessor(void *arg, const char *message);
 
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index 709869e88abe5849420dec799e280546bb1cb72a..48d2d77a5e8ec6a86f51f3280e72c836f416d597 100644
--- a/src/bin/psql/large_obj.c
+++ b/src/bin/psql/large_obj.c
@@ -14,7 +14,7 @@
 
 static void
 print_lo_result(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 static void
 print_lo_result(const char *fmt,...)
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index f9cbc137e72215e50a9e3e1e66e23a96f19ae6ab..3734afb468a50f3a56c6f70f0b5e4f66e91234d4 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -32,7 +32,7 @@ extern Form_pg_attribute attrtypes[MAXATTR];
 extern int	numattr;
 
 
-extern void AuxiliaryProcessMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void AuxiliaryProcessMain(int argc, char *argv[]) pg_attribute_noreturn;
 
 extern void err_out(void);
 
@@ -61,6 +61,6 @@ extern void boot_get_type_io_data(Oid typid,
 extern int	boot_yyparse(void);
 
 extern int	boot_yylex(void);
-extern void boot_yyerror(const char *str) __attribute__((noreturn));
+extern void boot_yyerror(const char *str) pg_attribute_noreturn;
 
 #endif   /* BOOTSTRAP_H */
diff --git a/src/include/c.h b/src/include/c.h
index ee615ee687f8249fed037136cfd0cc6027d1ccaa..a2d4a2c5c5d6b55a5b2090449afb82e86aea1dca 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -156,10 +156,6 @@
 #define dummyret	char
 #endif
 
-#ifndef __GNUC__
-#define __attribute__(_arg_)
-#endif
-
 /* ----------------------------------------------------------------
  *				Section 2:	bool, true, false, TRUE, FALSE, NULL
  * ----------------------------------------------------------------
@@ -560,6 +556,47 @@ typedef NameData *Name;
 /* we don't currently need wider versions of the other ALIGN macros */
 #define MAXALIGN64(LEN)			TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
 
+/* ----------------
+ * Attribute macros
+ *
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
+ * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
+ * ----------------
+ */
+
+/* only GCC supports the unused attribute */
+#ifdef __GNUC__
+#define pg_attribute_unused __attribute__((unused))
+#else
+#define pg_attribute_unused
+#endif
+
+/* GCC and XLC support format attributes */
+#if defined(__GNUC__) || defined(__IBMC__)
+#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
+#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
+#else
+#define pg_attribute_format_arg(a)
+#define pg_attribute_printf(f,a)
+#endif
+
+/* GCC, Sunpro and XLC support aligned, packed and noreturn */
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
+#define pg_attribute_aligned(a) __attribute__((aligned(a)))
+#define pg_attribute_noreturn __attribute__((noreturn))
+#define pg_attribute_packed __attribute__((packed))
+#else
+/*
+ * NB: aligned and packed are not defined as empty as they affect code
+ * functionality; they must be implemented by the compiler if they are to be
+ * used.
+ */
+#define pg_attribute_noreturn
+#endif
+
 /* ----------------------------------------------------------------
  *				Section 6:	assertions
  * ----------------------------------------------------------------
@@ -906,7 +943,7 @@ typedef NameData *Name;
 #ifdef USE_ASSERT_CHECKING
 #define PG_USED_FOR_ASSERTS_ONLY
 #else
-#define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused))
+#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused
 #endif
 
 
@@ -973,7 +1010,7 @@ typedef NameData *Name;
 extern int
 snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+pg_attribute_printf(3, 4);
 #endif
 
 #if !HAVE_DECL_VSNPRINTF
diff --git a/src/include/common/fe_memutils.h b/src/include/common/fe_memutils.h
index f7114c244f39decc4faa17d6c5762ed500f807f3..33123cb5044841c8c8baa1ab1a9512040f6926ab 100644
--- a/src/include/common/fe_memutils.h
+++ b/src/include/common/fe_memutils.h
@@ -26,9 +26,9 @@ extern void pfree(void *pointer);
 /* sprintf into a palloc'd buffer --- these are in psprintf.c */
 extern char *
 psprintf(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 extern size_t
 pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
+pg_attribute_printf(3, 0);
 
 #endif   /* FE_MEMUTILS_H */
diff --git a/src/include/lib/stringinfo.h b/src/include/lib/stringinfo.h
index 63d39e562181ac522bc231123dc5f53b1d917c31..fdb828508ea86a37aed78df259701abf90c1294e 100644
--- a/src/include/lib/stringinfo.h
+++ b/src/include/lib/stringinfo.h
@@ -95,7 +95,7 @@ extern void resetStringInfo(StringInfo str);
 extern void
 appendStringInfo(StringInfo str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 /*------------------------
  * appendStringInfoVA
@@ -108,7 +108,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
  */
 extern int
 appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
+pg_attribute_printf(2, 0);
 
 /*------------------------
  * appendStringInfoString
diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h
index 231003f85c701fa3f7568391bab3de7b8d577323..0a2234d35ac05485fec1d01fac7d2655c9fcc224 100644
--- a/src/include/mb/pg_wchar.h
+++ b/src/include/mb/pg_wchar.h
@@ -514,9 +514,9 @@ extern void check_encoding_conversion_args(int src_encoding,
 							   int expected_src_encoding,
 							   int expected_dest_encoding);
 
-extern void report_invalid_encoding(int encoding, const char *mbstr, int len) __attribute__((noreturn));
+extern void report_invalid_encoding(int encoding, const char *mbstr, int len) pg_attribute_noreturn;
 extern void report_untranslatable_char(int src_encoding, int dest_encoding,
-					   const char *mbstr, int len) __attribute__((noreturn));
+					   const char *mbstr, int len) pg_attribute_noreturn;
 
 extern void pg_ascii2mic(const unsigned char *l, unsigned char *p, int len);
 extern void pg_mic2ascii(const unsigned char *mic, unsigned char *p, int len);
diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h
index c886335e85b60ee7f7e90f72dacdd381d0d2a58d..fc0a2577f31438f02c01fdf4d149be33a4190ecc 100644
--- a/src/include/parser/parse_relation.h
+++ b/src/include/parser/parse_relation.h
@@ -85,9 +85,9 @@ extern bool isLockedRefname(ParseState *pstate, const char *refname);
 extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
 			  bool addToJoinList,
 			  bool addToRelNameSpace, bool addToVarNameSpace);
-extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) __attribute__((noreturn));
+extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) pg_attribute_noreturn;
 extern void errorMissingColumn(ParseState *pstate,
-	   char *relname, char *colname, int location) __attribute__((noreturn));
+	   char *relname, char *colname, int location) pg_attribute_noreturn;
 extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
 		  int location, bool include_dropped,
 		  List **colnames, List **colvars);
diff --git a/src/include/parser/scanner.h b/src/include/parser/scanner.h
index 535e864e3681ddd3cc464bd389874bd7204012b2..0e22d031f140d6a7472d33c8b03a17b02de82423 100644
--- a/src/include/parser/scanner.h
+++ b/src/include/parser/scanner.h
@@ -124,6 +124,6 @@ extern void scanner_finish(core_yyscan_t yyscanner);
 extern int core_yylex(core_YYSTYPE *lvalp, YYLTYPE *llocp,
 		   core_yyscan_t yyscanner);
 extern int	scanner_errposition(int location, core_yyscan_t yyscanner);
-extern void scanner_yyerror(const char *message, core_yyscan_t yyscanner) __attribute__((noreturn));
+extern void scanner_yyerror(const char *message, core_yyscan_t yyscanner) pg_attribute_noreturn;
 
 #endif   /* SCANNER_H */
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 30934d3ddf6bad473415732e6a8d4d25486e9ce5..64cc8e2e7c8f80a6480c78ad4d5165f3710971b0 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -875,7 +875,7 @@ extern void pgstat_reset_all(void);
 extern void allow_immediate_pgstat_restart(void);
 
 #ifdef EXEC_BACKEND
-extern void PgstatCollectorMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn;
 #endif
 
 
diff --git a/src/include/port.h b/src/include/port.h
index a1ab42e3da66482d30217120d220c04f61dd869b..b64651f1665b2a1f06d0b3782d07364e48da4b57 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -156,25 +156,25 @@ extern int	pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 extern int
 pg_snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+pg_attribute_printf(3, 4);
 extern int
 pg_sprintf(char *str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 extern int	pg_vfprintf(FILE *stream, const char *fmt, va_list args);
 extern int
 pg_fprintf(FILE *stream, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 extern int
 pg_printf(const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 /*
- *	The GCC-specific code below prevents the __attribute__(... 'printf')
- *	above from being replaced, and this is required because gcc doesn't
- *	know anything about pg_printf.
+ *	The GCC-specific code below prevents the pg_attribute_printf above from
+ *	being replaced, and this is required because gcc doesn't know anything
+ *	about pg_printf.
  */
 #ifdef __GNUC__
 #define vsnprintf(...)	pg_vsnprintf(__VA_ARGS__)
diff --git a/src/include/port/atomics/generic-gcc.h b/src/include/port/atomics/generic-gcc.h
index fea1cb5e1358754287e765fed423516b05a22c76..c9fc87b30d957e3939a3093d4c50ab3e5c1bac08 100644
--- a/src/include/port/atomics/generic-gcc.h
+++ b/src/include/port/atomics/generic-gcc.h
@@ -98,7 +98,7 @@ typedef struct pg_atomic_uint32
 
 typedef struct pg_atomic_uint64
 {
-	volatile uint64 value __attribute__((aligned(8)));
+	volatile uint64 value pg_attribute_aligned(8);
 } pg_atomic_uint64;
 
 #endif /* defined(HAVE_GCC__ATOMIC_INT64_CAS) || defined(HAVE_GCC__SYNC_INT64_CAS) */
diff --git a/src/include/port/atomics/generic-sunpro.h b/src/include/port/atomics/generic-sunpro.h
index 7a3028ec3d07964d331788ea93a46bc006bf1216..d369207fb34a41ede28bf7e125ec75fc34affedb 100644
--- a/src/include/port/atomics/generic-sunpro.h
+++ b/src/include/port/atomics/generic-sunpro.h
@@ -61,7 +61,7 @@ typedef struct pg_atomic_uint64
 	 * it proves to be a problem, we'll have to add more version checks for 64
 	 * bit support.
 	 */
-	volatile uint64 value __attribute__((__aligned__(8)));
+	volatile uint64 value pg_attribute_aligned(8);
 } pg_atomic_uint64;
 
 #endif /* HAVE_ATOMIC_H */
diff --git a/src/include/port/atomics/generic-xlc.h b/src/include/port/atomics/generic-xlc.h
index 7a4c12ae6cada2f9f0a890512e56af3fb61087f1..1c743f2bc80606df3cd5f8a68dcab302f2caf764 100644
--- a/src/include/port/atomics/generic-xlc.h
+++ b/src/include/port/atomics/generic-xlc.h
@@ -32,7 +32,7 @@ typedef struct pg_atomic_uint32
 #define PG_HAVE_ATOMIC_U64_SUPPORT
 typedef struct pg_atomic_uint64
 {
-	volatile uint64 value __attribute__((__aligned__(8)));
+	volatile uint64 value pg_attribute_aligned(8);
 } pg_atomic_uint64;
 
 #endif /* __64BIT__ */
diff --git a/src/include/postgres.h b/src/include/postgres.h
index cbb7f796e1ea553fbe68e64063902d0947d5ff70..ff30e05bfc844c94313858ca3319d4f12af97077 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -687,6 +687,6 @@ extern Datum Float8GetDatum(float8 X);
  */
 extern void ExceptionalCondition(const char *conditionName,
 					 const char *errorType,
-			 const char *fileName, int lineNumber) __attribute__((noreturn));
+			 const char *fileName, int lineNumber) pg_attribute_noreturn;
 
 #endif   /* POSTGRES_H */
diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h
index 121f1073871990398b78795287192c7304c6450b..0bd50443aeb9a1cd83cae81b391f7f380e384a18 100644
--- a/src/include/postmaster/autovacuum.h
+++ b/src/include/postmaster/autovacuum.h
@@ -54,8 +54,8 @@ extern void AutoVacWorkerFailed(void);
 extern void AutoVacuumUpdateDelay(void);
 
 #ifdef EXEC_BACKEND
-extern void AutoVacLauncherMain(int argc, char *argv[]) __attribute__((noreturn));
-extern void AutoVacWorkerMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn;
+extern void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn;
 extern void AutovacuumWorkerIAm(void);
 extern void AutovacuumLauncherIAm(void);
 #endif
diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h
index 81c03e4bb3bd04697315a719914bfb857b9d1744..fe7c328afd1b43c52b663222dd20698474e41f40 100644
--- a/src/include/postmaster/bgworker_internals.h
+++ b/src/include/postmaster/bgworker_internals.h
@@ -46,7 +46,7 @@ extern void BackgroundWorkerStopNotifications(pid_t pid);
 extern void ResetBackgroundWorkerCrashTimes(void);
 
 /* Function to start a background worker, called from postmaster.c */
-extern void StartBackgroundWorker(void) __attribute__((noreturn));
+extern void StartBackgroundWorker(void) pg_attribute_noreturn;
 
 #ifdef EXEC_BACKEND
 extern BackgroundWorker *BackgroundWorkerEntry(int slotno);
diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h
index ce12619797d2418c25b7a3b78a5a06c5201bee10..f584d85787215267d57c45be6cea76bca6aa86e8 100644
--- a/src/include/postmaster/bgwriter.h
+++ b/src/include/postmaster/bgwriter.h
@@ -25,8 +25,8 @@ extern int	CheckPointTimeout;
 extern int	CheckPointWarning;
 extern double CheckPointCompletionTarget;
 
-extern void BackgroundWriterMain(void) __attribute__((noreturn));
-extern void CheckpointerMain(void) __attribute__((noreturn));
+extern void BackgroundWriterMain(void) pg_attribute_noreturn;
+extern void CheckpointerMain(void) pg_attribute_noreturn;
 
 extern void RequestCheckpoint(int flags);
 extern void CheckpointWriteDelay(int flags, double progress);
diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h
index a585e6736c211a92d74a73db5be081a791ac6c73..60e4f50368d01286d89f9df9d17d0d21748bee1c 100644
--- a/src/include/postmaster/pgarch.h
+++ b/src/include/postmaster/pgarch.h
@@ -33,7 +33,7 @@
 extern int	pgarch_start(void);
 
 #ifdef EXEC_BACKEND
-extern void PgArchiverMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn;
 #endif
 
 #endif   /* _PGARCH_H */
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 91723f7d9af75f0a66f58b029c504a3982f9185b..d41761fc7a1f01487692822b5666a4d75b858eb9 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -46,7 +46,7 @@ extern int	postmaster_alive_fds[2];
 
 extern const char *progname;
 
-extern void PostmasterMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn;
 extern void ClosePostmasterPorts(bool am_syslogger);
 
 extern int	MaxLivePostmasterChildren(void);
@@ -56,7 +56,7 @@ extern bool PostmasterMarkPIDForWorkerNotify(int);
 
 #ifdef EXEC_BACKEND
 extern pid_t postmaster_forkexec(int argc, char *argv[]);
-extern void SubPostmasterMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void SubPostmasterMain(int argc, char *argv[]) pg_attribute_noreturn;
 
 extern Size ShmemBackendArraySize(void);
 extern void ShmemBackendArrayAllocation(void);
diff --git a/src/include/postmaster/startup.h b/src/include/postmaster/startup.h
index da1f6e933627965de2d26b8012d91bdf87fa6d74..9a2092e5f283cd64424e6003c463a922fa506e6f 100644
--- a/src/include/postmaster/startup.h
+++ b/src/include/postmaster/startup.h
@@ -13,7 +13,7 @@
 #define _STARTUP_H
 
 extern void HandleStartupProcInterrupts(void);
-extern void StartupProcessMain(void) __attribute__((noreturn));
+extern void StartupProcessMain(void) pg_attribute_noreturn;
 extern void PreRestoreCommand(void);
 extern void PostRestoreCommand(void);
 extern bool IsPromoteTriggered(void);
diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h
index 89a535c18fdef3288f18b30a6eadca18db64b132..d6a05d5a20903b7ee39964d9d23686e8ddce6bc4 100644
--- a/src/include/postmaster/syslogger.h
+++ b/src/include/postmaster/syslogger.h
@@ -84,7 +84,7 @@ extern int	SysLogger_Start(void);
 extern void write_syslogger_file(const char *buffer, int count, int dest);
 
 #ifdef EXEC_BACKEND
-extern void SysLoggerMain(int argc, char *argv[]) __attribute__((noreturn));
+extern void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn;
 #endif
 
 #endif   /* _SYSLOGGER_H */
diff --git a/src/include/postmaster/walwriter.h b/src/include/postmaster/walwriter.h
index de45a01f82da05fbb6b90051ed192a22233a8183..55de6c73e4a58429e93a93bb9cc9ddd9d5b1ec71 100644
--- a/src/include/postmaster/walwriter.h
+++ b/src/include/postmaster/walwriter.h
@@ -15,6 +15,6 @@
 /* GUC options */
 extern int	WalWriterDelay;
 
-extern void WalWriterMain(void) __attribute__((noreturn));
+extern void WalWriterMain(void) pg_attribute_noreturn;
 
 #endif   /* _WALWRITER_H */
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index defe8f982b164653213ef7c2a95d926fcc1c0565..4afdf91a6dc24461bd3bd36ee4118e50ea455394 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -147,7 +147,7 @@ typedef void (*walrcv_disconnect_type) (void);
 extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
 
 /* prototypes for functions in walreceiver.c */
-extern void WalReceiverMain(void) __attribute__((noreturn));
+extern void WalReceiverMain(void) pg_attribute_noreturn;
 
 /* prototypes for functions in walreceiverfuncs.c */
 extern Size WalRcvShmemSize(void);
diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h
index 54fa2ba57bb5a68497a2f2e6093ead4ed861854c..7da434e79870384f8c18f192698964e28c8f1033 100644
--- a/src/include/storage/ipc.h
+++ b/src/include/storage/ipc.h
@@ -64,7 +64,7 @@ typedef void (*shmem_startup_hook_type) (void);
 /* ipc.c */
 extern PGDLLIMPORT bool proc_exit_inprogress;
 
-extern void proc_exit(int code) __attribute__((noreturn));
+extern void proc_exit(int code) pg_attribute_noreturn;
 extern void shmem_exit(int code);
 extern void on_proc_exit(pg_on_exit_callback function, Datum arg);
 extern void on_shmem_exit(pg_on_exit_callback function, Datum arg);
diff --git a/src/include/storage/itemptr.h b/src/include/storage/itemptr.h
index 944812c4c015b7c4ecb062e781bec2296de19cc3..1f0ea7db55242295f93151a229242edd4fba21b3 100644
--- a/src/include/storage/itemptr.h
+++ b/src/include/storage/itemptr.h
@@ -41,7 +41,7 @@ typedef struct ItemPointerData
 }
 
 #ifdef __arm__
-__attribute__((packed))			/* Appropriate whack upside the head for ARM */
+pg_attribute_packed			/* Appropriate whack upside the head for ARM */
 #endif
 ItemPointerData;
 
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index 11009237866c3c3a870ff600e507bdd43d778835..1477a6fe3d1ce66bc8467b66d564a71daa129e7e 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -547,7 +547,7 @@ extern void lock_twophase_standby_recover(TransactionId xid, uint16 info,
 
 extern DeadLockState DeadLockCheck(PGPROC *proc);
 extern PGPROC *GetBlockingAutoVacuumPgproc(void);
-extern void DeadLockReport(void) __attribute__((noreturn));
+extern void DeadLockReport(void) pg_attribute_noreturn;
 extern void RememberSimpleDeadLock(PGPROC *proc1,
 					   LOCKMODE lockmode,
 					   LOCK *lock,
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index 3e17770e22a40d8b82d275d8e38ddf1bf6c80eb8..b3c705f97b69ceb7a0b5dbb9cd9e5bb4498f1aef 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -62,9 +62,9 @@ extern bool check_max_stack_depth(int *newval, void **extra, GucSource source);
 extern void assign_max_stack_depth(int newval, void *extra);
 
 extern void die(SIGNAL_ARGS);
-extern void quickdie(SIGNAL_ARGS) __attribute__((noreturn));
+extern void quickdie(SIGNAL_ARGS) pg_attribute_noreturn;
 extern void StatementCancelHandler(SIGNAL_ARGS);
-extern void FloatExceptionHandler(SIGNAL_ARGS) __attribute__((noreturn));
+extern void FloatExceptionHandler(SIGNAL_ARGS) pg_attribute_noreturn;
 extern void RecoveryConflictInterrupt(ProcSignalReason reason); /* called from SIGUSR1
 																 * handler */
 extern void ProcessClientReadInterrupt(bool blocked);
@@ -74,7 +74,7 @@ extern void process_postgres_switches(int argc, char *argv[],
 						  GucContext ctx, const char **dbname);
 extern void PostgresMain(int argc, char *argv[],
 			 const char *dbname,
-			 const char *username) __attribute__((noreturn));
+			 const char *username) pg_attribute_noreturn;
 extern long get_stack_depth_rlimit(void);
 extern void ResetUsage(void);
 extern void ShowUsage(const char *title);
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 6b8ab3c6564989cfcf410d5077a86278a574c5bc..3a2335523d070b5306e6336050f7b9b5fc0c113c 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -315,7 +315,7 @@ extern int DecodeISO8601Interval(char *str,
 					  int *dtype, struct pg_tm * tm, fsec_t *fsec);
 
 extern void DateTimeParseError(int dterr, const char *str,
-				   const char *datatype) __attribute__((noreturn));
+				   const char *datatype) pg_attribute_noreturn;
 
 extern int	DetermineTimeZoneOffset(struct pg_tm * tm, pg_tz *tzp);
 extern int	DetermineTimeZoneAbbrevOffset(struct pg_tm * tm, const char *abbr, pg_tz *tzp);
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index b5cfc9cbc88f141a55c0276fa1661b8ed6b6bfc2..a82063a57b1b78a8e46a6514716beae0e5a5938a 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -147,61 +147,61 @@ extern int
 errmsg(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int
 errmsg_internal(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int
 errmsg_plural(const char *fmt_singular, const char *fmt_plural,
 			  unsigned long n,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4)))
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4)));
+pg_attribute_printf(1, 4)
+pg_attribute_printf(2, 4);
 
 extern int
 errdetail(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int
 errdetail_internal(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int
 errdetail_log(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int
 errdetail_log_plural(const char *fmt_singular, const char *fmt_plural,
 					 unsigned long n,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4)))
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4)));
+pg_attribute_printf(1, 4)
+pg_attribute_printf(2, 4);
 
 extern int
 errdetail_plural(const char *fmt_singular, const char *fmt_plural,
 				 unsigned long n,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4)))
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4)));
+pg_attribute_printf(1, 4)
+pg_attribute_printf(2, 4);
 
 extern int
 errhint(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 /*
  * errcontext() is typically called in error context callback functions, not
@@ -218,7 +218,7 @@ extern int
 errcontext_msg(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 extern int	errhidestmt(bool hide_stmt);
 extern int	errhidecontext(bool hide_ctx);
@@ -278,7 +278,7 @@ extern void
 elog_finish(int elevel, const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 
 /* Support for constructing error strings separately from ereport() calls */
@@ -288,7 +288,7 @@ extern char *
 format_elog_string(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 
 /* Support for attaching context information to error reports */
@@ -364,7 +364,7 @@ extern PGDLLIMPORT ErrorContextCallback *error_context_stack;
 	} while (0)
 
 /*
- * gcc understands __attribute__((noreturn)); for other compilers, insert
+ * gcc understands pg_attribute_noreturn; for other compilers, insert
  * pg_unreachable() so that the compiler gets the point.
  */
 #ifdef __GNUC__
@@ -423,9 +423,9 @@ extern void EmitErrorReport(void);
 extern ErrorData *CopyErrorData(void);
 extern void FreeErrorData(ErrorData *edata);
 extern void FlushErrorState(void);
-extern void ReThrowError(ErrorData *edata) __attribute__((noreturn));
+extern void ReThrowError(ErrorData *edata) pg_attribute_noreturn;
 extern void ThrowErrorData(ErrorData *edata);
-extern void pg_re_throw(void) __attribute__((noreturn));
+extern void pg_re_throw(void) pg_attribute_noreturn;
 
 extern char *GetErrorContextStack(void);
 
@@ -472,6 +472,6 @@ extern void
 write_stderr(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 
 #endif   /* ELOG_H */
diff --git a/src/include/utils/help_config.h b/src/include/utils/help_config.h
index 481687f25fdf65cc426cdf25c925bddf16fecc8b..af529964003161df96a963903248b629a5c5f2ee 100644
--- a/src/include/utils/help_config.h
+++ b/src/include/utils/help_config.h
@@ -12,6 +12,6 @@
 #ifndef HELP_CONFIG_H
 #define HELP_CONFIG_H 1
 
-extern void GucInfoMain(void) __attribute__((noreturn));
+extern void GucInfoMain(void) pg_attribute_noreturn;
 
 #endif
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index 39b318da43aca64aad9b8f31b87428c4b74756a7..bd8767520e33b882da700fb27b87ff451a62d3be 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -138,9 +138,9 @@ extern char *pnstrdup(const char *in, Size len);
 /* sprintf into a palloc'd buffer --- these are in psprintf.c */
 extern char *
 psprintf(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 extern size_t
 pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
+pg_attribute_printf(3, 0);
 
 #endif   /* PALLOC_H */
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index ca3bf05181690385f88b46374ba08c5f793b0e6f..1fa21fd84ace46ce2278e64f9bc47eaddd1263ac 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -185,7 +185,7 @@ void		ecpg_raise(int line, int code, const char *sqlstate, const char *str);
 void		ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
 char	   *ecpg_prepared(const char *, struct connection *);
 bool		ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
-void		ecpg_log(const char *format,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+void		ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
 bool		ecpg_auto_prepare(int, const char *, const int, char **, const char *);
 void		ecpg_init_sqlca(struct sqlca_t * sqlca);
 
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index 3b8ed4c4b03331668aa53abf67ef9431defa2f7a..5efe59351f12e9a2189e0703767d32db0c6ab272 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -15,7 +15,7 @@
 #ifdef ENABLE_NLS
 extern char *
 ecpg_gettext(const char *msgid)
-__attribute__((format_arg(1)));
+pg_attribute_format_arg(1);
 #else
 #define ecpg_gettext(x) (x)
 #endif
diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header
index a2be29c4348ae1de094affc4bf619221f63ffafd..e23407ec8d31c26726ed481278172209d62643bb 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -64,7 +64,7 @@ static struct ECPGtype ecpg_query = {ECPGt_char_variable, NULL, NULL, NULL, {NUL
 /*
  * Handle parsing errors and warnings
  */
-static void __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)))
+static void pg_attribute_printf(3, 0)
 vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
 {
 	/* localize the error message string */
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index dfc75bceec2e93abeb184dc4b392803b258294fd..1ce25ebe1bb7038153a1f53ad18635df7c629c96 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -77,8 +77,8 @@ extern int	base_yylex(void);
 extern void base_yyerror(const char *);
 extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
 extern char *mm_strdup(const char *);
-extern void mmerror(int errorcode, enum errortype type, const char *error,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
-extern void mmfatal(int errorcode, const char *error,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
+extern void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3, 4);
+extern void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2, 3) pg_attribute_noreturn;
 extern void output_get_descr_header(char *);
 extern void output_get_descr(char *, char *);
 extern void output_set_descr_header(char *);
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 64579d294044b3558cd91617592a19364eb66be2..b9b630a222ffd09b4f7a85bb87bfc0be616edfdb 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -548,7 +548,7 @@ extern PGresult *pqPrepareAsyncResult(PGconn *conn);
 extern void
 pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 extern void pqSaveMessageField(PGresult *res, char code,
 				   const char *value);
 extern void pqSaveParameterStatus(PGconn *conn, const char *name,
@@ -653,10 +653,10 @@ extern ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len);
 #ifdef ENABLE_NLS
 extern char *
 libpq_gettext(const char *msgid)
-__attribute__((format_arg(1)));
+pg_attribute_format_arg(1);
 extern char *
 libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n)
-__attribute__((format_arg(1))) __attribute__((format_arg(2)));
+pg_attribute_format_arg(1) pg_attribute_format_arg(2);
 #else
 #define libpq_gettext(x) (x)
 #define libpq_ngettext(s, p, n) ((n) == 1 ? (s) : (p))
diff --git a/src/interfaces/libpq/pqexpbuffer.c b/src/interfaces/libpq/pqexpbuffer.c
index 15117a3d1730da10df05b60a797a7136745d562a..43df56a1e09de00375f8caa90f9e396eabf8ce69 100644
--- a/src/interfaces/libpq/pqexpbuffer.c
+++ b/src/interfaces/libpq/pqexpbuffer.c
@@ -39,7 +39,7 @@ static const char oom_buffer[1] = "";
 
 static bool
 appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
+pg_attribute_printf(2, 0);
 
 
 /*
diff --git a/src/interfaces/libpq/pqexpbuffer.h b/src/interfaces/libpq/pqexpbuffer.h
index 3598271fa9e191ba070e9bb871b73d53bc1ab657..345d20376b825ef49a52a65900100912fce881bd 100644
--- a/src/interfaces/libpq/pqexpbuffer.h
+++ b/src/interfaces/libpq/pqexpbuffer.h
@@ -149,7 +149,7 @@ extern int	enlargePQExpBuffer(PQExpBuffer str, size_t needed);
 extern void
 printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 /*------------------------
  * appendPQExpBuffer
@@ -161,7 +161,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 extern void
 appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 /*------------------------
  * appendPQExpBufferStr
diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c
index 4d2497afe9d8584c8dc53cdee216c92cb97c1c0a..04c5ed4b724d3aaaac8eaab696b908c33f110e4b 100644
--- a/src/interfaces/libpq/win32.c
+++ b/src/interfaces/libpq/win32.c
@@ -36,7 +36,7 @@
 #ifdef ENABLE_NLS
 extern char *
 libpq_gettext(const char *msgid)
-__attribute__((format_arg(1)));
+pg_attribute_format_arg(1);
 #else
 #define libpq_gettext(x) (x)
 #endif
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index 89bbd7ccb0dc124013aa5882de179d848d623561..aadb888393089b2cb2673c65fe269bb3b5fb1c54 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -30,9 +30,7 @@
  * Supply a value of PERL_UNUSED_DECL that will satisfy gcc - the one
  * perl itself supplies doesn't seem to.
  */
-#if defined(__GNUC__)
-#define PERL_UNUSED_DECL __attribute__ ((unused))
-#endif
+#define PERL_UNUSED_DECL pg_attribute_unused
 
 /*
  * Sometimes perl carefully scribbles on our *printf macros.
diff --git a/src/pl/plpgsql/src/pl_scanner.c b/src/pl/plpgsql/src/pl_scanner.c
index ec08b02a2137b0f241aa0bfd3f23eede03b4d42f..f9323771e69814ebc48318dcaab4207880d892e1 100644
--- a/src/pl/plpgsql/src/pl_scanner.c
+++ b/src/pl/plpgsql/src/pl_scanner.c
@@ -608,7 +608,7 @@ plpgsql_scanner_errposition(int location)
  * be misleading!
  */
 void
-__attribute__((noreturn))
+pg_attribute_noreturn
 plpgsql_yyerror(const char *message)
 {
 	char	   *yytext = core_yy.scanbuf + plpgsql_yylloc;
diff --git a/src/pl/plpython/plpy_elog.h b/src/pl/plpython/plpy_elog.h
index 6b8d485625be54d9bdc6ff120bdf48bea3da0d05..e4e4dfb695d8a5a94faa8427c310e44cab7503ae 100644
--- a/src/pl/plpython/plpy_elog.h
+++ b/src/pl/plpython/plpy_elog.h
@@ -12,16 +12,16 @@ extern PyObject *PLy_exc_spi_error;
 
 extern void
 PLy_elog(int elevel, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 extern void
 PLy_exception_set(PyObject *exc, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 extern void
 PLy_exception_set_plural(PyObject *exc, const char *fmt_singular, const char *fmt_plural,
 						 unsigned long n,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 5)))
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 5)));
+pg_attribute_printf(2, 5)
+pg_attribute_printf(3, 5);
 
 #endif   /* PLPY_ELOG_H */
diff --git a/src/test/modules/test_shm_mq/test_shm_mq.h b/src/test/modules/test_shm_mq/test_shm_mq.h
index 144345b611bf1488481ed1d094f75c522d3efb98..94d28805ff52f48a77545ed499b0b43a89650002 100644
--- a/src/test/modules/test_shm_mq/test_shm_mq.h
+++ b/src/test/modules/test_shm_mq/test_shm_mq.h
@@ -40,6 +40,6 @@ extern void test_shm_mq_setup(int64 queue_size, int32 nworkers,
 				  shm_mq_handle **input);
 
 /* Main entrypoint for a worker. */
-extern void test_shm_mq_main(Datum) __attribute__((noreturn));
+extern void test_shm_mq_main(Datum) pg_attribute_noreturn;
 
 #endif
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 94d3857364f59e6ef84ba2571771a34c9b06f1b3..4149c94d30274a1f25cce61e28acd8e610e18756 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -46,7 +46,7 @@ PG_MODULE_MAGIC;
 PG_FUNCTION_INFO_V1(worker_spi_launch);
 
 void		_PG_init(void);
-void		worker_spi_main(Datum) __attribute__((noreturn));
+void		worker_spi_main(Datum) pg_attribute_noreturn;
 
 /* flags set by signal handlers */
 static volatile sig_atomic_t got_sighup = false;
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 3af0e57d4e3ba24f2e5c1880e141db0f36ac9208..9d4fb9a5a58812534176710ed91f5583c3fcedad 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -135,17 +135,17 @@ static void
 header(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 static void
 status(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+pg_attribute_printf(1, 2);
 static void
 psql_command(const char *database, const char *query,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+pg_attribute_printf(2, 3);
 
 #ifdef WIN32
 typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);