Fix .altinstructions linking failures
PATCH 1/1 Fix .altinstructions linking failures
Some configs didn't link anymore because they got references from .altinstructions to __exit functions. Fixing it at the linker level is not easily possible. This patch just discards .text.exit at runtime instead of link time to avoid this.
Idea from Andrew Morton.
It will also fix a related problem with .eh_frame in modern gcc (so far only observed on x86-64, but could happen on i386 too)
Index: linux/arch/i386/vmlinux.lds.S
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/vmlinux.lds.S,v retrieving revision 1.18
arch/i386/vmlinux.lds.S +4 -2
@@ -85,7 +85,10 @@ __alt_instructions = .; .altinstructions : { *(.altinstructions) } __alt_instructions_end = .; - .altinstr_replacement : { *(.altinstr_replacement) } + .altinstr_replacement : { *(.altinstr_replacement) } + /* .exit.text is discard at runtime, not link time, to deal with references + from .altinstructions and .eh_frame */ + .exit.text : { *(.exit.text) } . = ALIGN(4096); __initramfs_start = .; .init.ramfs : { *(.init.ramfs) }
@@ -106,7 +109,6 @@ /* Sections to be discarded */ /DISCARD/ : { - *(.exit.text) *(.exit.data) *(.exitcall.exit) }
Quoted 32 lines · Andi Kleen
Some configs didn't link anymore because they got references from .altinstructions to
__exitfunctions. Fixing it at the linker level is not easily possible. This patch just discards .text.exit at runtime instead of link time to avoid this.Idea from Andrew Morton.
It will also fix a related problem with .eh_frame in modern gcc (so far only observed on x86-64, but could happen on i386 too)
Index:
linux/arch/i386/vmlinux.lds.S
===================================================================
RCS file:/home/cvs/linux-2.5/arch/i386/vmlinux.lds.S,vretrieving revision 1.18
diff -u -u -r1.18vmlinux.lds.Sarch/i386/vmlinux.lds.S +4
-1@@ -85,7 +85,10 @@ __alt_instructions = .; .altinstructions : { *(.altinstructions) } __alt_instructions_end = .; - .altinstr_replacement : { *(.altinstr_replacement) } + .altinstr_replacement : { *(.altinstr_replacement) } + /* .exit.text is discard at runtime, not link time, to deal with references + from .altinstructions and .eh_frame */ + .exit.text : { *(.exit.text) } . = ALIGN(4096); __initramfs_start = .; .init.ramfs : { *(.init.ramfs) }
arch/i386/vmlinux.lds.S line 114
Quoted 7 lines
arch/i386/vmlinux.lds.S +0
-1@@ -106,7 +109,6 @@ /* Sections to be discarded */ /DISCARD/ : { - *(.exit.text) *(.exit.data) *(.exitcall.exit) }
This patch is bogus.
The result are tons of
undefined reference to `local symbols in discarded section .exit.data'
This problem might be solved by moving the .exit.data, too.
The next thing that breaks are things like the following:
drivers/built-in.o(.exit.text+0x4c25): In function `cpia_exit':
: undefined reference to `proc_cpia_destroy'
The problem is in drivers/media/video/cpia.c:
<-- snip -->
...
#ifdef MODULE
static void proc_cpia_destroy(void)
{
remove_proc_entry("cpia", 0);
}#endif /*MODULE*/
...
static void __exit cpia_exit(void)
{
#ifdef CONFIG_PROC_FS
proc_cpia_destroy();#endif
}
...
<-- snip -->
Please fix all of the problems your changes in 2.5.69 created.
TIA
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 8 lines · Adrian Bunk
<-- snip -->
...
#ifdef MODULE
static voidproc_cpia_destroy(void){ remove_proc_entry("cpia", 0); }
Quoted 8 lines
#endif /*MODULE*/
...
static void__exitcpia_exit(void)
{#ifdef CONFIG_PROC_FS proc_cpia_destroy();#endif
}
The driver is buggy. The #ifdef MODULE needs to be removed and proc_cpia_destroy be marked __exit instead, then things will be ok.
-Andi
Quoted 2 lines · Andi Kleen
The driver is buggy. The #ifdef MODULE needs to be removed and
proc_cpia_destroybe marked__exitinstead, then things will be ok.
FWIW I compiled a "maxi kernel" now (with everything that compiles compiled in) and only cpia seems to have this bug. So with this patch things should be ok again.
-Andi
Index: linux/drivers/media/video/cpia.c
===================================================================
RCS file: /home/cvs/linux-2.5/drivers/media/video/cpia.c,v retrieving revision 1.25
drivers/media/video/cpia.c +1 -3
@@ -1409,12 +1409,10 @@LOG ("Unable to initialise /proc/cpia\n" ); } -#ifdef MODULE -static void proc_cpia_destroy (void ) +static void __exit proc_cpia_destroy(void) {remove_proc_entry ("cpia" ,0 ); } -#endif /*MODULE*/ #endif /* CONFIG_PROC_FS */ /* ----------------------- debug functions ---------------------- */
Quoted 8 lines · Andi Kleen
Quoted 2 lines · Andi Kleen
The driver is buggy. The #ifdef MODULE needs to be removed and
proc_cpia_destroybe marked__exitinstead, then things will be ok.FWIW I compiled a "maxi kernel" now (with everything that compiles compiled in) and only cpia seems to have this bug. So with this patch things should be ok again.
Where should we be discarding .exit.data? link-time or runtime?
Quoted 11 lines · Andrew Morton
Quoted 8 lines · Andi Kleen
Quoted 2 lines · Andi Kleen
The driver is buggy. The #ifdef MODULE needs to be removed and
proc_cpia_destroybe marked__exitinstead, then things will be ok.FWIW I compiled a "maxi kernel" now (with everything that compiles compiled in) and only cpia seems to have this bug. So with this patch things should be ok again.
Where should we be discarding .exit.data? link-time or runtime?
Run time is probably safer.
-Andi
Quoted 10 lines · Andi Kleen
Some configs didn't link anymore because they got references from .altinstructions to
__exitfunctions. Fixing it at the linker level is not easily possible. This patch just discards .text.exit at runtime instead of link time to avoid this.Idea from Andrew Morton.
It will also fix a related problem with .eh_frame in modern gcc (so far only observed on x86-64, but could happen on i386 too)
But it sure won't make any embedded people happy. This adds .text.exit (and .data.exit?) to the kernel image, which is nothing but unnecessary bloat. Nothing inside those sections is ever used, yet their footprint does hurt on small systems.
I've been a bit sceptical of the whole .altinstructions idea, self-modifying code opens a can of worms for anyone trying to do code analysis (coverage, verification,...). But with this followup, I personally pay money to get that stuff ripped out again.
Jörn
Signature · 3 lines
The cost of changing business rules is much more expensive for software than for a secretaty. -- unknown
[cc list trimmed]
Quoted 4 lines · Jörn Engel
I've been a bit sceptical of the whole .altinstructions idea, self-modifying code opens a can of worms for anyone trying to do code analysis (coverage, verification,...). But with this followup, I personally pay money to get that stuff ripped out again.
Ok. How much do you pay ? ;@)
Seriously. To give some numbers. This is the maxi kernel (about 8MB .text, everything compiled in that compiles in 2.5.69) which is far too big to even even boot.
20 .exit.text 00005afa c0ada3d0 c0ada3d0 009db3d0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
About 20k from 8MB
On a realistic kernel that actually boots we are talking about 1-2KB, probably even less. If you really wanted to combat bloat there are a lot other areas where you can avoid much more than 2KB with minimum effort. Just go through include/linux/* and move a few unnecessary inlines away, that will help much more. If you want to save real memory attack mem_map, like I proposed earlier.
-Andi
P.S.: In case someone is interested: The hall of shame for the 2.5.69 SMP maxi kernel (stuff that doesn't build) currently is: Sound/Alsa (one driver doesn't compile), USB (3 drivers don't compile), MTD (lots of stuff doesn't compile). Everything else is quite good.
Quoted 11 lines · Andi Kleen
Seriously. To give some numbers. This is the maxi kernel (about 8MB .text, everything compiled in that compiles in 2.5.69) which is far too big to even even boot.
20 .exit.text
00005afac0ada3d0c0ada3d0009db3d02**4
CONTENTS, ALLOC, LOAD, READONLY, CODEAbout 20k from 8MB
On a realistic kernel that actually boots we are talking about 1-2KB, probably even less.
Sounds more like 1/2 maxi to me, but you are basically right. 2-3k on one of my production embedded kernels. I can accept that, but it doesn't really make me happy.
Quoted 5 lines
If you really wanted to combat bloat there are a lot
other areas where you can avoid much more than 2KB with minimum effort. Just go throughinclude/linux/*and move a few unnecessary inlines away, that will help much more. If you want to save real memory attackmem_map, like I proposed earlier.
Still on my list, but I didn't get to it yet.
Quoted 4 lines
P.S.: In case someone is interested: The hall of shame for the 2.5.69 SMP maxi kernel (stuff that doesn't build) currently is: Sound/Alsa (one driver doesn't compile), USB (3 drivers don't compile), MTD (lots of stuff doesn't compile). Everything else is quite good.
Do you have a .config for that kernel. I tried to create a maximal one for 2.5.69 as well, but the problems in the Subject: stopped me and ld didn't give me enough clues, which drivers to remove.
Jörn
Signature · 3 lines
When people work hard for you for a pat on the back, you've got to give them that pat. -- Robert Heinlein
Quoted 1 line · Andi Kleen
USB (3 drivers don't compile)
What 3 USB drivers do not compile in the current tree?
thanks,
greg k-h
Quoted 5 lines · Andi Kleen
...
P.S.: In case someone is interested: The hall of shame for the 2.5.69 SMP maxi kernel (stuff that doesn't build) currently is: Sound/Alsa (one driver doesn't compile), USB (3 drivers don't compile), MTD (lots of stuff doesn't compile). Everything else is quite good.
At about a dozen SCSI drivers plus half a dozen drivers under drivers/char/* don't compile in 2.5.69 even for non-SMP. How did you manage to compile these?
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 9 lines · Adrian Bunk
Quoted 4 lines · Andi Kleen
P.S.: In case someone is interested: The hall of shame for the 2.5.69 SMP maxi kernel (stuff that doesn't build) currently is: Sound/Alsa (one driver doesn't compile), USB (3 drivers don't compile), MTD (lots of stuff doesn't compile). Everything else is quite good.At about a dozen SCSI drivers plus half a dozen drivers under
drivers/char/*don't compile in 2.5.69 even for non-SMP. How did you manage to compile these?
Just so we can name those drivers, this is the diff between my maximal config for 2.5.69 and allyesconfig. Well, for easier reading, it is piped through grep '^-'.
Is this list of any interest? Should I generate it regularly for newer kernels? Would anyone actually read it and fix things?
Jörn
Signature · 298 lines
Sometimes, asking the right question is already the answer. -- Unknown -CONFIG_X86_GENERIC=y -CONFIG_X86_L1_CACHE_SHIFT=7 -CONFIG_X86_INTEL_USERCOPY=y -CONFIG_SMP=y -CONFIG_NR_CPUS=32 -CONFIG_EISA_VLB_PRIMING=y -CONFIG_HOTPLUG_PCI_ACPI=y -CONFIG_MTD_BLOCK=y -CONFIG_MTD_UCLINUX=y -CONFIG_MTD_BLKMTD=y -CONFIG_SCSI_AIC7XXX=y -CONFIG_AIC7XXX_CMDS_PER_DEVICE=32 -CONFIG_AIC7XXX_RESET_DELAY_MS=15000 -CONFIG_AIC7XXX_PROBE_EISA_VL=y -CONFIG_AIC7XXX_BUILD_FIRMWARE=y -CONFIG_AIC7XXX_DEBUG_ENABLE=y -CONFIG_AIC7XXX_DEBUG_MASK=0 -CONFIG_AIC7XXX_REG_PRETTY_PRINT=y -CONFIG_SCSI_AIC7XXX_OLD=y -CONFIG_SCSI_AIC79XX=y -CONFIG_AIC79XX_CMDS_PER_DEVICE=32 -CONFIG_AIC79XX_RESET_DELAY_MS=15000 -CONFIG_AIC79XX_BUILD_FIRMWARE=y -CONFIG_AIC79XX_ENABLE_RD_STRM=y -CONFIG_AIC79XX_DEBUG_ENABLE=y -CONFIG_AIC79XX_DEBUG_MASK=0 -CONFIG_AIC79XX_REG_PRETTY_PRINT=y -CONFIG_SCSI_DPT_I2O=y -CONFIG_SCSI_AM53C974=y -CONFIG_SCSI_CPQFCTS=y -CONFIG_SCSI_GENERIC_NCR5380=y -CONFIG_SCSI_GENERIC_NCR5380_MMIO=y -CONFIG_SCSI_GENERIC_NCR53C400=y -CONFIG_SCSI_INITIO=y -CONFIG_SCSI_INIA100=y -CONFIG_SCSI_MCA_53C9X=y -CONFIG_SCSI_PCI2000=y -CONFIG_SCSI_PCI2220I=y -CONFIG_SCSI_PSI240I=y -CONFIG_SCSI_DC395x=y -CONFIG_SCSI_DC390T=y -CONFIG_SCSI_DC390T_NOGENSUPP=y -CONFIG_DECNET=y -CONFIG_DECNET_SIOCGIFCONF=y -CONFIG_DECNET_ROUTER=y -CONFIG_DECNET_ROUTE_FWMARK=y -CONFIG_IXGB=y -CONFIG_IXGB_NAPI=y -CONFIG_DEFXX=y -CONFIG_STRIP=y -CONFIG_TMS380TR=y -CONFIG_TMSPCI=y -CONFIG_SKISA=y -CONFIG_PROTEON=y -CONFIG_ABYSS=y -CONFIG_MADGEMC=y -CONFIG_IPHASE5526=y -CONFIG_RCPCI=y -CONFIG_VENDOR_SANGOMA=y -CONFIG_WANPIPE_CHDLC=y -CONFIG_WANPIPE_FR=y -CONFIG_WANPIPE_X25=y -CONFIG_WANPIPE_PPP=y -CONFIG_WANPIPE_MULTPPP=y -CONFIG_6PACK=y -CONFIG_DMASCC=y -CONFIG_ISDN=y -CONFIG_ISDN_NET_SIMPLE=y -CONFIG_ISDN_NET_CISCO=y -CONFIG_ISDN_PPP=y -CONFIG_ISDN_PPP_VJ=y -CONFIG_ISDN_MPP=y -CONFIG_ISDN_PPP_BSDCOMP=y -CONFIG_ISDN_AUDIO=y -CONFIG_ISDN_TTY_FAX=y - -# -# ISDN feature submodules -# -CONFIG_ISDN_DRV_LOOP=y -CONFIG_ISDN_DIVERSION=y -CONFIG_ISDN_CAPI_CAPIDRV=y -# ISDN4Linux hardware drivers -# - -# -# Passive cards -# -CONFIG_ISDN_DRV_HISAX=y - -# -# D-channel protocol features -# -CONFIG_HISAX_EURO=y -CONFIG_DE_AOC=y -CONFIG_HISAX_NO_SENDCOMPLETE=y -CONFIG_HISAX_NO_LLC=y -CONFIG_HISAX_NO_KEYPAD=y -CONFIG_HISAX_1TR6=y -CONFIG_HISAX_NI1=y -CONFIG_HISAX_MAX_CARDS=8 - -# -# HiSax supported cards -# -CONFIG_HISAX_16_0=y -CONFIG_HISAX_16_3=y -CONFIG_HISAX_TELESPCI=y -CONFIG_HISAX_S0BOX=y -CONFIG_HISAX_AVM_A1=y -CONFIG_HISAX_FRITZPCI=y -CONFIG_HISAX_AVM_A1_PCMCIA=y -CONFIG_HISAX_ELSA=y -CONFIG_HISAX_IX1MICROR2=y -CONFIG_HISAX_DIEHLDIVA=y -CONFIG_HISAX_ASUSCOM=y -CONFIG_HISAX_TELEINT=y -CONFIG_HISAX_HFCS=y -CONFIG_HISAX_SEDLBAUER=y -CONFIG_HISAX_SPORTSTER=y -CONFIG_HISAX_MIC=y -CONFIG_HISAX_NETJET=y -CONFIG_HISAX_NETJET_U=y -CONFIG_HISAX_NICCY=y -CONFIG_HISAX_ISURF=y -CONFIG_HISAX_HSTSAPHIR=y -CONFIG_HISAX_BKM_A4T=y -CONFIG_HISAX_SCT_QUADRO=y -CONFIG_HISAX_GAZEL=y -CONFIG_HISAX_HFC_PCI=y -CONFIG_HISAX_W6692=y -CONFIG_HISAX_HFC_SX=y -CONFIG_HISAX_ENTERNOW_PCI=y -CONFIG_HISAX_DEBUG=y -CONFIG_HISAX_SEDLBAUER_CS=y -CONFIG_HISAX_ELSA_CS=y -CONFIG_HISAX_AVM_A1_CS=y -CONFIG_HISAX_ST5481=y -CONFIG_HISAX_FRITZ_PCIPNP=y -CONFIG_HISAX_FRITZ_CLASSIC=y -CONFIG_HISAX_HFCPCI=y - -# -# Active cards -# -CONFIG_ISDN_DRV_ICN=y -CONFIG_ISDN_DRV_PCBIT=y -CONFIG_ISDN_DRV_SC=y -CONFIG_ISDN_DRV_ACT2000=y -CONFIG_ISDN_DRV_EICON=y -# CONFIG_ISDN_DRV_EICON_DIVAS is not set -CONFIG_ISDN_DRV_EICON_OLD=y -CONFIG_ISDN_DRV_EICON_PCI=y -# CONFIG_ISDN_DRV_EICON_ISA is not set -CONFIG_ISDN_DRV_TPAM=y -CONFIG_HYSDN=m -CONFIG_HYSDN_CAPI=y - -# -CONFIG_ROCKETPORT=y -CONFIG_DIGIEPCA=y -CONFIG_ESPSERIAL=y -CONFIG_RISCOM8=y -CONFIG_SPECIALIX=y -CONFIG_SPECIALIX_RTSCTS=y -CONFIG_SX=y -CONFIG_RIO=y -CONFIG_RIO_OLDPCI=y -CONFIG_STALLION=y -CONFIG_ISTALLION=y -CONFIG_SCx200_I2C=y -CONFIG_SCx200_I2C_SCL=12 -CONFIG_SCx200_I2C_SDA=13 -CONFIG_SENSORS_ADM1021=y -CONFIG_SENSORS_IT87=y -CONFIG_SENSORS_LM75=y -CONFIG_SENSORS_VIA686A=y -CONFIG_SENSORS_W83781D=y -CONFIG_I2C_SENSOR=y -CONFIG_IPMI_HANDLER=y -CONFIG_IPMI_PANIC_EVENT=y -CONFIG_IPMI_DEVICE_INTERFACE=y -CONFIG_IPMI_KCS=y -CONFIG_IPMI_WATCHDOG=y -CONFIG_SONYPI=y -CONFIG_MWAVE=y -CONFIG_VIDEO_CPIA=y -CONFIG_VIDEO_CPIA_PP=y -CONFIG_VIDEO_CPIA_USB=y -CONFIG_VIDEO_ZORAN=y -CONFIG_VIDEO_ZORAN_BUZ=y -CONFIG_VIDEO_ZORAN_DC10=y -CONFIG_VIDEO_ZORAN_LML33=y -CONFIG_VIDEO_ZR36120=y -CONFIG_VIDEO_MEYE=y -CONFIG_RADIO_MIROPCM20_RDS=y -CONFIG_NEC98_PARTITION=y -CONFIG_FB_CIRRUS=y -CONFIG_FB_PM2=y -CONFIG_FB_PM2_FIFO_DISCONNECT=y -CONFIG_FB_PM2_PCI=y -CONFIG_FB_I810=y -CONFIG_FB_I810_GTF=y -CONFIG_FB_MATROX=y -CONFIG_FB_MATROX_MILLENIUM=y -CONFIG_FB_MATROX_MYSTIQUE=y -CONFIG_FB_MATROX_G450=y -CONFIG_FB_MATROX_G100=y -CONFIG_FB_MATROX_I2C=y -CONFIG_FB_MATROX_MAVEN=y -CONFIG_FB_MATROX_MULTIHEAD=y -CONFIG_FB_PM3=y -CONFIG_SND_AD1816A=y -CONFIG_SND_CS4232=y -CONFIG_SND_CS4236=y -CONFIG_SND_ES18XX=y -CONFIG_SND_INTERWAVE=y -CONFIG_SND_INTERWAVE_STB=y -CONFIG_SND_OPTI92X_AD1848=y -CONFIG_SND_OPTI92X_CS4231=y -CONFIG_SND_OPTI93X=y -CONFIG_SND_SBAWE=y -CONFIG_SND_WAVEFRONT=y -CONFIG_SND_CMI8330=y -CONFIG_SND_OPL3SA2=y -CONFIG_SND_ICE1712=y -CONFIG_SOUND_MSNDCLAS=y - -# -# Compiled-in MSND Classic support requires firmware during compilation. -# -CONFIG_MSNDCLAS_HAVE_BOOT=y -CONFIG_MSNDCLAS_INIT_FILE="/etc/sound/msndinit.bin" -CONFIG_MSNDCLAS_PERM_FILE="/etc/sound/msndperm.bin" -CONFIG_MSNDCLAS_IRQ=5 -CONFIG_MSNDCLAS_MEM=0xD0000 -CONFIG_MSNDCLAS_IO=0x290 -CONFIG_SOUND_MSNDPIN=y - -# -# Compiled-in MSND Pinnacle support requires firmware during compilation. -# -CONFIG_MSNDPIN_HAVE_BOOT=y -CONFIG_MSNDPIN_INIT_FILE="/etc/sound/pndspini.bin" -CONFIG_MSNDPIN_PERM_FILE="/etc/sound/pndsperm.bin" -CONFIG_MSNDPIN_IRQ=5 -CONFIG_MSNDPIN_MEM=0xD0000 -CONFIG_MSNDPIN_IO=0x290 -CONFIG_MSNDPIN_DIGITAL=y -CONFIG_MSNDPIN_NONPNP=y - -# -# MSND Pinnacle DSP section will be configured to above parameters. -# -CONFIG_MSNDPIN_CFG=0x250 - -# -# Pinnacle-specific Device Configuration (0 disables) -# -CONFIG_MSNDPIN_MPU_IO=0x0 -CONFIG_MSNDPIN_MPU_IRQ=0 -CONFIG_MSNDPIN_IDE_IO0=0x0 -CONFIG_MSNDPIN_IDE_IO1=0x0 -CONFIG_MSNDPIN_IDE_IRQ=0 -CONFIG_MSNDPIN_JOYSTICK_IO=0x0 -CONFIG_MSND_FIFOSIZE=128 -CONFIG_SOUND_AD1816=y -CONFIG_SOUND_CS4232=y -CONFIG_SOUND_GUS=y -CONFIG_SOUND_GUS16=y -CONFIG_SOUND_GUSMAX=y -CONFIG_TRIX_HAVE_BOOT=y -CONFIG_TRIX_BOOT_FILE="/etc/sound/trxpro.hex" -CONFIG_SOUND_MAD16=y -CONFIG_MAD16_OLDCARD=y -CONFIG_PSS_HAVE_BOOT=y -CONFIG_PSS_BOOT_FILE="/etc/sound/dsp001.ld" -CONFIG_SOUND_AWE32_SYNTH=y -CONFIG_MAUI_HAVE_BOOT=y -CONFIG_MAUI_BOOT_FILE="/etc/sound/oswf.mot" -CONFIG_USB_AN2720=y -CONFIG_USB_BELKIN=y -CONFIG_USB_GENESYS=y -CONFIG_USB_NET1080=y -CONFIG_USB_PL2301=y -CONFIG_USB_ARMLINUX=y -CONFIG_USB_EPSON2888=y -CONFIG_USB_ZAURUS=y -CONFIG_USB_SERIAL_CONSOLE=y -CONFIG_BT_HCIUSB=y -CONFIG_BT_USB_SCO=y -CONFIG_BT_USB_ZERO_PACKET=y -CONFIG_X86_SMP=y -CONFIG_X86_HT=y -CONFIG_X86_TRAMPOLINE=y