clang built kernel runs on qemu

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

clang built kernel runs on qemu

rgcinjp
ppc@

here's a quick n dirty update about macppc and clang

after checking out the specs i agree with George's assertions about
the validity of the different code generated by clang
[Subject: Re: clang build kernel traps]
so i gave everything a try again with his patches.


a) applied a base-clang patch from George Koehler
[Subject: [ports] [macppc] devel/llvm: add clang -msvr4-struct-return]

ls -la `which clang`
-r-xr-xr-x  3 root  bin  52656676 Feb  4 18:47 /usr/bin/clang*


b) modify bsd.own.mk && install

cvs diff: Diffing .
Index: bsd.own.mk
===================================================================
RCS file: /home/cvs/src/share/mk/bsd.own.mk,v
retrieving revision 1.200
diff -u -p -r1.200 bsd.own.mk
--- bsd.own.mk  6 Sep 2019 15:07:19 -0000       1.200
+++ bsd.own.mk  4 Feb 2020 10:33:06 -0000
@@ -16,7 +16,7 @@ SKEY?=                yes
 YP?=           yes

 CLANG_ARCH=aarch64 amd64 arm i386 mips64 mips64el powerpc sparc64
-GCC4_ARCH=alpha hppa mips64el powerpc sh sparc64
+GCC4_ARCH=alpha hppa mips64el sh sparc64
 GCC3_ARCH=m88k
 LLD_ARCH=aarch64 amd64 arm i386


c) build ofwboot
OpenBSD/macppc BOOT 1.7"x" for experimental
CC=clang CXX=clang++ CPP=clang-cpp make


d) build kernel
CC=clang CXX=clang++ CPP=clang-cpp make


e) create simple cd iso
get ofwboot, get kernel
modify the tbxi a bit to get bsd.gdb booting
only contains RAMDISK kernel no filesystem


f) fire up qemu

time qemu-system-ppc -M mac99,via=pmu-adb -cpu g4 \
-nodefaults -nographic -serial mon:stdio -net none \
-boot d -cdrom install66.iso $@ 2> stderr 1> stdout


s>> et_property: NULL phandle

>> =============================================================
>> OpenBIOS 1.1 [Jul 1 2019 17:09]
>> Configuration device id QEMU version 1 machine id 1
>> CPUs: 1
>> Memory: 128M
>> UUID: 00000000-0000-0000-0000-000000000000
>> CPU type PowerPC,G4
milliseconds isn't unique.
Welcome to OpenBIOS v1.1 built on Jul 1 2019 17:09
Trying cd:,\\:tbxi...
>> switching to new context:
>> OpenBSD/macppc BOOT 1.7x
|/-\|/-\boot>
|/-\cannot open /pci@f2000000/mac-io@c/ata-3@21000/cdrom@0:/etc/random.seed: No such file or directory
booting /pci@f2000000/mac-io@c/ata-3@21000/cdrom@0:/6.6/macppc/bsd.gdb: |/-\|/-8269508\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\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|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-+185748\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-]=0x100114
string [/cdrom@0:/6.6/macppc/bsd.gdb] not found
Warning: boot device unrecognized: /pci@f2000000/mac-io@c/ata-3@21000/cdrom@0:/6.6/macppc/bsd.gdb
Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2020 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 6.6-current (RAMDISK) #0: Tue Feb  4 21:27:20 JST 2020
    [hidden email]:/home/rgc/work/clang-kern/src/sys/arch/macppc/compile/RAMDISK
real mem = 134217728 (128MB)
avail mem = 104710144 (99MB)
mainbus0 at root: model PowerMac3,1
cpu0 at mainbus0: 7400 (Revision 0x209): 900 MHz: L2 cache not enabled
mem at mainbus0 not configured
mpcpcibr0 at mainbus0 pci: uni-north
pci0 at mpcpcibr0 bus 0
macobio0 at pci0 dev 12 function 0 "Apple Keylargo" rev 0x00
macgpio0 at macobio0 offset 0x50
macgpio1 at macgpio0 offset 0x9: irq 47
"programmer-switch" at macgpio0 not configured
adb0 at macobio0 offset 0x16000: irq 25, via-pmu, 2 targets
akbd0 at adb0 addr 2: extended keyboard
wskbd0 at akbd0 mux 1
relative positioning device (3) at adb0 addr 3 not configured
zs0 at macobio0 offset 0x13000: irq 37,36
zstty0 at zs0 channel 0: console
zstty1 at zs0 channel 1
"escc-legacy" at macobio0 offset 0x12000 not configured
wdc0 at macobio0 offset 0x20000 irq 13: DMA
wdc1 at macobio0 offset 0x21000 irq 14: DMA
atapiscsi0 at wdc1 channel 0 drive 0
scsibus0 at atapiscsi0: 2 targets
cd0 at scsibus0 targ 0 lun 0: <QEMU, QEMU DVD-ROM, 2.5+> removable
cd0(wdc1:0:0): using BIOS timings, DMA mode 2
openpic0 at macobio0 offset 0x40000: version 0x0 feature 3f0002 LE
panic: trap type 300 srr1 9032 at 2b7890 (0+0x2b7890) lr 2dbb9c
halted

EXIT
0 > QEMU 4.1.0 monitor - type 'help' for more information
(qemu)
(qemu) qququiquit
    9m47.11s real     2m31.11s user     0m06.94s system


running GENERIC on qemu is not really a good idea.
when a full backup finishes. i'll run a GENERIC kernel on my G4.


btw, noob here so if i missed anything kindly point it out to me.

yorosiku ~

Reply | Threaded
Open this post in threaded view
|

Re: clang built kernel runs on qemu

rgcinjp
On Tue, Feb 04, 2020 at 10:23:09PM +0900, rgc wrote:
> ppc@
>
> here's a quick n dirty update about macppc and clang
> :
> :
> when a full backup finishes. i'll run a GENERIC kernel on my G4.

a) clang-compiled kernel and gcc-compiled (stock) ofwboot NG
stops after initializing Jasper

b) clang-compiled kernel and clang-compiled ofwboot NG
stops after initializing Jasper

i can get on UKC on both

it is something to check this weekend


yorosiku ~

Reply | Threaded
Open this post in threaded view
|

Re: clang built kernel runs on qemu

George Koehler-2
In reply to this post by rgcinjp
On Tue, 4 Feb 2020 22:23:09 +0900
rgc <[hidden email]> wrote:

> a) applied a base-clang patch from George Koehler
> [Subject: [ports] [macppc] devel/llvm: add clang -msvr4-struct-return]
>
> ls -la `which clang`
> -r-xr-xr-x  3 root  bin  52656676 Feb  4 18:47 /usr/bin/clang*

Here is a copy of the base-clang patch for ppc@.
(I will send it to tech@ in a moment.)

The patch changes the ABI for functions returning small structs, so
the ABI becomes compatible with gcc.  I have not seen any such functions
in the kernel, so the patch might not help with kernel builds.

Apply the patch to /usr/src/gnu/llvm, then build clang like

# cd /usr/src/gnu/usr.bin/clang
# make obj
# make
# make install

If you have less than 1024M RAM, then the build might be too slow.
My iMac G3 with 512M RAM got stuck (using over 800M swap) trying to
build the ports-clang patch that I sent to ports@,
  https://marc.info/?l=openbsd-ports&m=158026852003182&w=2

--George

Index: tools/clang/include/clang/Driver/Options.td
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/include/clang/Driver/Options.td,v
retrieving revision 1.11
diff -u -p -r1.11 Options.td
--- tools/clang/include/clang/Driver/Options.td 23 Jun 2019 22:05:15 -0000 1.11
+++ tools/clang/include/clang/Driver/Options.td 30 Jan 2020 01:13:29 -0000
@@ -2238,6 +2238,12 @@ def mlongcall: Flag<["-"], "mlongcall">,
     Group<m_ppc_Features_Group>;
 def mno_longcall : Flag<["-"], "mno-longcall">,
     Group<m_ppc_Features_Group>;
+def maix_struct_return : Flag<["-"], "maix-struct-return">,
+  Group<m_Group>, Flags<[CC1Option]>,
+  HelpText<"Return all structs in memory (PPC32 only)">;
+def msvr4_struct_return : Flag<["-"], "msvr4-struct-return">,
+  Group<m_Group>, Flags<[CC1Option]>,
+  HelpText<"Return small structs in registers (PPC32 only)">;
 
 def mvx : Flag<["-"], "mvx">, Group<m_Group>;
 def mno_vx : Flag<["-"], "mno-vx">, Group<m_Group>;
Index: tools/clang/lib/CodeGen/TargetInfo.cpp
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp,v
retrieving revision 1.1.1.7
diff -u -p -r1.1.1.7 TargetInfo.cpp
--- tools/clang/lib/CodeGen/TargetInfo.cpp 23 Jun 2019 21:37:39 -0000 1.1.1.7
+++ tools/clang/lib/CodeGen/TargetInfo.cpp 30 Jan 2020 01:13:30 -0000
@@ -4092,12 +4092,24 @@ namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
+  bool IsRetSmallStructInRegABI;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
 
 public:
-  PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI)
-      : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI) {}
+  PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
+                     bool RetSmallStructInRegABI)
+      : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
+        IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override {
+    if (!getCXXABI().classifyReturnType(FI))
+      FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+    for (auto &I : FI.arguments())
+      I.info = classifyArgumentType(I.type);
+  }
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
                     QualType Ty) const override;
@@ -4105,8 +4117,13 @@ public:
 
 class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC32TargetCodeGenInfo(CodeGenTypes &CGT, bool SoftFloatABI)
-      : TargetCodeGenInfo(new PPC32_SVR4_ABIInfo(CGT, SoftFloatABI)) {}
+  PPC32TargetCodeGenInfo(CodeGenTypes &CGT, bool SoftFloatABI,
+                         bool RetSmallStructInRegABI)
+      : TargetCodeGenInfo(new PPC32_SVR4_ABIInfo(CGT, SoftFloatABI,
+                                                 RetSmallStructInRegABI)) {}
+
+  static bool isStructReturnInRegABI(const llvm::Triple &Triple,
+                                     const CodeGenOptions &Opts);
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
     // This is recovered from gcc output.
@@ -4142,6 +4159,34 @@ CharUnits PPC32_SVR4_ABIInfo::getParamTy
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
+  uint64_t Size;
+
+  // -msvr4-struct-return puts small aggregates in GPR3 and GPR4.
+  if (isAggregateTypeForABI(RetTy) && IsRetSmallStructInRegABI &&
+      (Size = getContext().getTypeSize(RetTy)) <= 64) {
+    // System V ABI (1995), page 3-22, specified:
+    // > A structure or union whose size is less than or equal to 8 bytes
+    // > shall be returned in r3 and r4, as if it were first stored in the
+    // > 8-byte aligned memory area and then the low addressed word were
+    // > loaded into r3 and the high-addressed word into r4.  Bits beyond
+    // > the last member of the structure or union are not defined.
+    //
+    // GCC for big-endian PPC32 inserts the pad before the first member,
+    // not "beyond the last member" of the struct.  To stay compatible
+    // with GCC, we coerce the struct to an integer of the same size.
+    // LLVM will extend it and return i32 in r3, or i64 in r3:r4.
+    if (Size == 0)
+      return ABIArgInfo::getIgnore();
+    else {
+      llvm::Type *CoerceTy = llvm::Type::getIntNTy(getVMContext(), Size);
+      return ABIArgInfo::getDirect(CoerceTy);
+    }
+  }
+
+  return DefaultABIInfo::classifyReturnType(RetTy);
+}
+
 // TODO: this implementation is now likely redundant with
 // DefaultABIInfo::EmitVAArg.
 Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
@@ -4299,6 +4344,25 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(Co
   return Result;
 }
 
+bool PPC32TargetCodeGenInfo::isStructReturnInRegABI(
+    const llvm::Triple &Triple, const CodeGenOptions &Opts) {
+  assert(Triple.getArch() == llvm::Triple::ppc);
+
+  switch (Opts.getStructReturnConvention()) {
+  case CodeGenOptions::SRCK_Default:
+    break;
+  case CodeGenOptions::SRCK_OnStack: // -maix-struct-return
+    return false;
+  case CodeGenOptions::SRCK_InRegs: // -msvr4-struct-return
+    return true;
+  }
+
+  if (Triple.isOSBinFormatELF() && !Triple.isOSLinux())
+    return true;
+
+  return false;
+}
+
 bool
 PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                                 llvm::Value *Address) const {
@@ -9330,9 +9394,13 @@ const TargetCodeGenInfo &CodeGenModule::
     return SetCGInfo(new ARMTargetCodeGenInfo(Types, Kind));
   }
 
-  case llvm::Triple::ppc:
+  case llvm::Triple::ppc: {
+    bool RetSmallStructInRegABI =
+        PPC32TargetCodeGenInfo::isStructReturnInRegABI(Triple, CodeGenOpts);
     return SetCGInfo(
-        new PPC32TargetCodeGenInfo(Types, CodeGenOpts.FloatABI == "soft"));
+        new PPC32TargetCodeGenInfo(Types, CodeGenOpts.FloatABI == "soft",
+                                   RetSmallStructInRegABI));
+  }
   case llvm::Triple::ppc64:
     if (Triple.isOSBinFormatELF()) {
       PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv1;
Index: tools/clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp,v
retrieving revision 1.20
diff -u -p -r1.20 Clang.cpp
--- tools/clang/lib/Driver/ToolChains/Clang.cpp 25 Oct 2019 00:40:56 -0000 1.20
+++ tools/clang/lib/Driver/ToolChains/Clang.cpp 30 Jan 2020 01:13:30 -0000
@@ -3870,6 +3870,19 @@ void Clang::ConstructJob(Compilation &C,
     CmdArgs.push_back(A->getValue());
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
+                               options::OPT_msvr4_struct_return)) {
+    if (TC.getArch() != llvm::Triple::ppc) {
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << A->getSpelling() << RawTriple.str();
+    } else if (A->getOption().matches(options::OPT_maix_struct_return)) {
+      CmdArgs.push_back("-maix-struct-return");
+    } else {
+      assert(A->getOption().matches(options::OPT_msvr4_struct_return));
+      CmdArgs.push_back("-msvr4-struct-return");
+    }
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
                                options::OPT_freg_struct_return)) {
     if (TC.getArch() != llvm::Triple::x86) {
Index: tools/clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Frontend/CompilerInvocation.cpp,v
retrieving revision 1.4
diff -u -p -r1.4 CompilerInvocation.cpp
--- tools/clang/lib/Frontend/CompilerInvocation.cpp 23 Jun 2019 22:05:15 -0000 1.4
+++ tools/clang/lib/Frontend/CompilerInvocation.cpp 30 Jan 2020 01:13:30 -0000
@@ -1199,11 +1199,18 @@ static bool ParseCodeGenArgs(CodeGenOpti
       Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
   }
 
-  if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) {
-    if (A->getOption().matches(OPT_fpcc_struct_return)) {
+  // X86_32 has -fppc-struct-return and -freg-struct-return.
+  // PPC32 has -maix-struct-return and -msvr4-struct-return.
+  if (Arg *A =
+          Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return,
+                          OPT_maix_struct_return, OPT_msvr4_struct_return)) {
+    const Option &O = A->getOption();
+    if (O.matches(OPT_fpcc_struct_return) ||
+        O.matches(OPT_maix_struct_return)) {
       Opts.setStructReturnConvention(CodeGenOptions::SRCK_OnStack);
     } else {
-      assert(A->getOption().matches(OPT_freg_struct_return));
+      assert(O.matches(OPT_freg_struct_return) ||
+             O.matches(OPT_msvr4_struct_return));
       Opts.setStructReturnConvention(CodeGenOptions::SRCK_InRegs);
     }
   }

Reply | Threaded
Open this post in threaded view
|

Re: clang built kernel runs on qemu

rgcinjp
In reply to this post by rgcinjp
ppc@

On Wed, Feb 05, 2020 at 05:52:47AM +0900, rgc wrote:

> On Tue, Feb 04, 2020 at 10:23:09PM +0900, rgc wrote:
> > ppc@
> >
> > here's a quick n dirty update about macppc and clang
> > :
> > :
> > when a full backup finishes. i'll run a GENERIC kernel on my G4.
>
> a) clang-compiled kernel and gcc-compiled (stock) ofwboot NG
> stops after initializing Jasper
>
> b) clang-compiled kernel and clang-compiled ofwboot NG
> stops after initializing Jasper
>
> i can get on UKC on both
>
> it is something to check this weekend

i dived head first, eyes closed to a deep pit ... it seems

things i've noticed ... these are mainly diferences in the
generated code by gcc and clang.

1 clang is generating .data.rel.ro sections even when -fno-pie
is used in the compile option

but ... ld handles it.


2 clang generates code R_PPC_PLTREL code, from the lists it
is an optimazation that should be handled by the linker ...

again ld handles it.


3 clang defaults to -fstack-protector-strong according to
clang-local(1) and was verified in the actual llvm code.

current gcc just uses -fstack-protector, the lowest level
by default.

the RAMDISK has -fno-stack-protector ... if i compile
GENERIC with NO_PROPOLICE (which also forces the use of
-fno-stack-protector) the kernel boots until it hits
a Data Access exception ... which might have been caused
by either #1 or #2 above.


i have VERY ugly mdifications for llvm for #1 and #2 but
even with those, the boot does not progress much (well
i get several periphs detected on qemu).

yorosiku ~