@@ -0,0 +1,30 @@
+#!/bin/sh
+
+case "$1" in
+ as|*/as|*-as) ;;
+ *) exec "$@"
+esac
+
+real_as=$1
+shift
+
+out=a.out
+in=-
+
+while [ $# != 0 ]; do
+ case "$1" in
+ -o)
+ out=$2
+ shift
+ ;;
+ *.s)
+ in=$1
+ ;;
+ *)
+ args=$args\ $1
+ esac
+ shift
+done
+
+gasfilter <"$in" \
+| "$real_as" $args -o "$out"
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $xpushsection_defined;
+
+my @section_stack = ( undef );
+
+sub setsection ($$) {
+ my ($name, $line) = @_;
+
+ print ".purgem __xpushsection\n" if $xpushsection_defined;
+
+ print
+".macro __xpushsection name:req, flags
+ .pushsection \"$name.\\name\", \"\\flags\"
+.endm
+";
+
+ $section_stack[$#section_stack] = $name;
+
+ $xpushsection_defined = 1;
+
+ print $line
+}
+
+sub popsection ($)
+{
+ pop @section_stack;
+ setsection $section_stack[$#section_stack], $_[0];
+}
+
+sub pushsection ($$)
+{
+ my ($name, $line) = @_;
+
+ push @section_stack, $name;
+ setsection $name, $line;
+}
+
+sub xpushsection ($$) {
+ my ($name, $rest) = @_;
+
+ print "__xpushsection \"$name\"$rest\n"
+}
+
+sub process_line {
+ $_ = $_[0] if defined $_[0];
+
+ if (/^\s*(\.(text|data|bss))(\s|$)/) {
+ setsection $1, $_
+ } elsif (/^\s*\.section\s+([\$._0-9A-Za-z]+).*/) {
+ setsection $1, $_
+ } elsif (/^\s*\.pushsection\s+([\$._0-9A-Za-z]+).*/) {
+ pushsection $1, $_
+ } elsif (/^\s*\.popsection(\s|$)/) {
+ popsection $_
+ } elsif (/^\s*\.xpushsection\s+([\$._0-9A-Za-z]+)(.*)/) {
+ xpushsection $1, $2
+ } elsif (/^\s*\.xpopsection(\s|$)/) {
+ print ".popsection\n"
+ } else {
+ print
+ }
+}
+
+process_line ".text\n";
+process_line while <>;
@@ -0,0 +1,23 @@
+.macro fixup
+ _fixup \@
+.endm
+
+.macro _fixup num
+__fixup_\num :
+ .xpushsection fixup, "a"
+ .long __fixup_\num
+ .xpopsection
+.endm
+
+.globl main
+main:
+ fixup
+ nop
+
+.section .text.init, "ax"
+.globl init
+init: nop
+
+ fixup
+ nop
+