Skip to contentSkip to conversation

Use -fno-unit-at-a-time if gcc supports it

PATCH David Mosberger-Tang 2 participants 2 messages Sep 6, 2003 – Sep 8, 2003 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

For what it's worth, it was straight-forward to get the ia64 linux kernel to compile & boot with the latest gcc snapshot. I could make a patch, if anyone cares, but it was mostly trival stuff: a small cleanup in init_task.c and a few changes in init.h/compiler.h to use "attribute ((used))".

Even the wait-channels seem to come out right, though I'm not sure what's being done there is guaranteed to continue to work as the compiler gets more aggressive...

	--david

--
Interested in learning more about IA-64 Linux? Try http://www.lia64.org/book/

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jan Hubicka

On Fri, 2003-09-05 at 11:17, Andreas Jaeger wrote:

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Since unit-at-a-time has better inlining heuristics the better

way is > to add the used attribute - but that takes some time. The short-term > solution would be to add the compiler flag,

Won't we get a linker error if a static symbol is used but optimized-away? It shouldn't be hard to fix the n linker errors that crop up.

Jan> Yes, you get linker error. You may also run into Jan> misscompilation assuiming that function is static and it is Jan> both called by hand in asm and by function call and there is Jan> missing attribute used and asmlinkage definition. In that case Jan> GCC would conclude to change into register calling convention Jan> on i386 breaking asm code.

Jan> I would expect this to be rare as functions tends to be used Jan> either by assembly or by normal code but not by both.

Quoted 2 lines
Quoted 2 lines

And why are we using static symbols in inline assembly outside
of the compilation scope?

Jan> The toplevel asm statements are common source of this at least Jan> in glibc. I didn't look much into the kernel sources.

Jan> I would be very happy if someone did look on that. It may be Jan> well possible that implementing tricks you do currently with Jan> toplevel asm staements would need further extensions in GCC now Jan> and it would be nice to know about that.

Jan> For instance it used to be possible to force function to go Jan> into given section by changing the section by hand, but now you Jan> have to use section attribute (that is cleaner anyway)

Quoted 12 lines
Quoted 12 lines

Anyhow, if it generates an error, this isn't hard to fix.

Here is the start...

Robert Love

include/linux/compiler.h Fri Sep 5 12:02:02 2003 @@ renamed from include/linux/compiler.h Fri Sep 5 11:57:56 2003 +0 -1
-74,6 +74,19 @@ #define __attribute_pure__ /* unimplemented */

#endif

Quoted 8 lines
Quoted 8 lines

+/* + * As of gcc 3.2, we can mark a function as 'used' and gcc will assume that, + * even if it does not find a reference to it in any compilation unit. We + * need this for gcc 3.4 and beyond, which can optimize on a program-wide + * scope, and not just one file at a time, to avoid static symbols being + * discarded. + */ +#if (__GNUC__ == 3 && __GNUC_MINOR__ > 1) || __GNUC__ > 3 +#define __attribute_used__ __attribute__((used)) +#else +#define __attribute_used__ /* unimplemented */ +#endif +

Jan> I believe there is little trick - attribute used works either Jan> for variables or functions. Functions can be marked as used Jan> only for GCC 3.4+ if I am right, so you may need Jan> __attribute_used_function__ and __attribute_used_variable__ Jan> macros for that.

Jan> Honza

Quoted 5 lines
Quoted 5 lines

/* This macro obfuscates arithmetic on a variable address so that gcc shouldn't recognize the original var, and make assumptions about it */ #define RELOC_HIDE(ptr, off) \

Jan> - To unsubscribe from this list: send the line "unsubscribe Jan> linux-kernel" in the body of a message to
Jan> [email protected] More majordomo info at Jan> http://vger.kernel.org/majordomo-info.html Please read the FAQ Jan> at http://www.tux.org/lkml/

#5 lore raw

Here is a minimal platform-independent patch which lets me build the ia64 kernel with the current gcc-pre3.4 snapshot (which optimizes away static variables which have no compiler-visible references). All it does is mark the init-call macros with "__attribute_unused__" (plus a minor whitespace fix).

I did have to add an include of <linux/compiler.h> to <linux/init.h>. That ought to be safe, because the only other include file used by these files is <linux/config.h>.

Please apply, if there are no objections.

Thanks,

	--david

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1305 -> 1.1306
# include/linux/init.h 1.26 -> 1.27
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/09/08 [email protected] 1.1306
# Mark initcall macros with __attribute_used__ so the definitions do not

# get optimized away by the compiler (such as the latest GCC pre-3.4).
# --------------------------------------------
#
diff -Nru a/include/linux/init.h b/include/linux/init.h
--- a/include/linux/init.h	Mon Sep  8 13:28:21 2003
+++ b/include/linux/init.h	Mon Sep  8 13:28:21 2003
@@ -2,6 +2,7 @@
 #define _LINUX_INIT_H

#include <linux/config.h>
+#include <linux/compiler.h>

/* These macros are used to mark some functions or
* initialized data (doesn't apply to uninitialized data)
@@ -71,15 +72,16 @@

#ifndef __ASSEMBLY__

-/* initcalls are now grouped by functionality into separate +/* initcalls are now grouped by functionality into separate
* subsections. Ordering inside the subsections is determined
- * by link order.
- * For backwards compatibility, initcall() puts the call in
+ * by link order.
+ * For backwards compatibility, initcall() puts the call in
* the device init subsection.
*/

-#define __define_initcall(level,fn) \
- static initcall_t __initcall_##fn __attribute__ ((unused,__section__ (".initcall" level ".init"))) = fn
+#define __define_initcall(level,fn) \
+ static initcall_t __initcall_##fn \
+ __attribute_used__ __attribute__ ((__section__ (".initcall" level ".init"))) = fn

#define core_initcall(fn) __define_initcall("1",fn)
#define postcore_initcall(fn) __define_initcall("2",fn)
@@ -95,10 +97,12 @@
static exitcall_t __exitcall_##fn __exit_call = fn

#define console_initcall(fn) \
- static initcall_t __initcall_##fn __attribute__ ((unused,__section__ (".con_initcall.init")))=fn
+ static initcall_t __initcall_##fn \
+ __attribute_used__ __attribute__ ((__section__ (".con_initcall.init"))) = fn

#define security_initcall(fn) \
- static initcall_t __initcall_##fn __attribute__ ((unused,__section__ (".security_initcall.init"))) = fn
+ static initcall_t __initcall_##fn \
+ __attribute_used__ __attribute__ ((__section__ (".security_initcall.init"))) = fn

struct obs_kernel_param {
const char *str;
@@ -106,10 +110,10 @@
};

/* OBSOLETE: see moduleparam.h for the right way. */
-#define __setup(str, fn) \
- static char __setup_str_##fn[] __initdata = str; \
- static struct obs_kernel_param __setup_##fn \
- __attribute__((unused,__section__ (".init.setup"))) \
+#define __setup(str, fn) \
+ static char __setup_str_##fn[] __initdata = str; \
+ static struct obs_kernel_param __setup_##fn \
+ __attribute_used__ __attribute__((__section__ (".init.setup"))) \
= { __setup_str_##fn, fn }

#endif /* __ASSEMBLY__ */