Solaris 64-Bit Developer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
Solaris 64-bit Developer’s Guide Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. Part No: 816–5138–10 January 2005 Copyright 2005 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, docs.sun.com, AnswerBook, AnswerBook2, and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and Sun™ Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun’s written license agreements. U.S. Government Rights – Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright 2005 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Tous droits réservés. Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, par quelque moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y en a. Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et licencié par des fournisseurs de Sun. Des parties de ce produit pourront être dérivées du système Berkeley BSD licenciés par l’Université de Californie. UNIX est une marque déposée aux Etats-Unis et dans d’autres pays et licenciée exclusivement par X/Open Company, Ltd. Sun, Sun Microsystems, le logo Sun, docs.sun.com, AnswerBook, AnswerBook2, et Solaris sont des marques de fabrique ou des marques déposées, de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc. aux Etats-Unis et dans d’autres pays. Les produits portant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc. L’interface d’utilisation graphique OPEN LOOK et Sun™ a été développée par Sun Microsystems, Inc. pour ses utilisateurs et licenciés. Sun reconnaît les efforts de pionniers de Xerox pour la recherche et le développement du concept des interfaces d’utilisation visuelle ou graphique pour l’industrie de l’informatique. Sun détient une licence non exclusive de Xerox sur l’interface d’utilisation graphique Xerox, cette licence couvrant également les licenciés de Sun qui mettent en place l’interface d’utilisation graphique OPEN LOOK et qui en outre se conforment aux licences écrites de Sun. CETTE PUBLICATION EST FOURNIE “EN L’ETAT” ET AUCUNE GARANTIE, EXPRESSE OU IMPLICITE, N’EST ACCORDEE, Y COMPRIS DES GARANTIES CONCERNANT LA VALEUR MARCHANDE, L’APTITUDE DE LA PUBLICATION A REPONDRE A UNE UTILISATION PARTICULIERE, OU LE FAIT QU’ELLE NE SOIT PAS CONTREFAISANTE DE PRODUIT DE TIERS. CE DENI DE GARANTIE NE S’APPLIQUERAIT PAS, DANS LA MESURE OU IL SERAIT TENU JURIDIQUEMENT NUL ET NON AVENU. 041013@10082 Contents Preface 7 1 64-bit Computing 13 Getting Past the 4 Gigabyte Barrier 13 Beyond Large Address Spaces 15 2 When to Use 64-bit 17 Major Features 18 Large Virtual Address Space 18 Large Files 19 64–bit Arithmetic 19 System Limitations Removed 19 Interoperability Issues 19 Kernel Memory Readers 19 /proc Restrictions 20 64–bit Libraries 20 Estimating the Effort of Conversion 20 3 Comparing 32-bit Interfaces and 64–bit Interfaces 21 Application Programming Interfaces 21 Application Binary Interfaces 22 Compatibility Between 32-bit Applications and 64–bit Applications 22 Application Binaries 22 Application Source Code 22 Device Drivers 23 3 Which Solaris Operating Environment Are You Running? 23 4 Converting Applications 25 Data Model 25 Implementing Single-Source Code 28 Feature Test Macros 28 Derived Types 28 <sys/types.h> File 28 <inttypes.h> File 29 Tools Support 32 lint for 32–bit and 64–bit Environments 32 Guidelines for Converting to LP64 34 Do Not Assume int and Pointers Are the Same Size 34 Do Not Assume int and long Are the Same Size 35 Sign Extension 35 Use Pointer Arithmetic Instead of Address Arithmetic 37 Repacking a Structure 37 Check Unions 38 Specify Constant Types 38 Beware of Implicit Declaration 39 sizeof is an unsigned long 39 Use Casts to Show Your Intentions 40 Check Format String Conversion Operation 40 Other Considerations 41 Derived Types That Have Grown in Size 41 Use #ifdef for Explicit 32-bit Versus 64-bit Prototypes 42 Algorithmic Changes 42 Checklist for Getting Started 42 Sample Program 43 5 The Development Environment 45 Build Environment 45 Header Files 45 Compiler Environments 47 32-bit and 64-bit Libraries 47 Linking Object Files 48 LD_LIBRARY_PATH Environment Variable 48 4 Solaris 64-bit Developer’s Guide • January 2005 $ORIGIN Keyword 48 Packaging 32-bit and 64-bit Applications 49 Placement of Libraries and Programs 49 Packaging Guidelines 50 Application Naming Conventions 50 Shell-Script Wrappers 50 /usr/lib/isaexec Binary File 51 isaexec(3c) Interface 52 Debugging 64-bit Applications 52 6 Advanced Topics 53 SPARC V9 ABI Features 53 Stack Bias 54 Address Space Layout of the SPARC V9 ABI 55 Placement of Text and Data of the SPARC V9 ABI 55 Code Models of the SPARC V9 ABI 56 AMD64 ABI Features 57 Address Space Layout for amd64 Applications 58 Alignment Issues 59 Interprocess Communication 60 ELF and System Generation Tools 61 /proc Interface 61 Extensions to sysinfo(2) 62 libkvm and /dev/ksyms 62 libkstat Kernel Statistics 63 Changes to stdio 63 Performance Issues 64 64-bit Application Advantages 64 64-bit Application Disadvantages 64 System Call Issues 64 What Does EOVERFLOW Mean? 64 Beware ioctl() 65 5 A Changes in Derived Types 67 B Frequently Asked Questions (FAQs) 71 Index 73 6 Solaris 64-bit Developer’s Guide • January 2005 Preface The capabilities of the Solaris™ operating environment continue to expand to meet customer needs. The Solaris operating environment was designed to fully support both the 32-bit and 64-bit architectures. The Solaris operating environment provides an environment for building and running 64-bit applications that can use large files and large virtual address spaces. At the same time, the Solaris operating environment continues to provide maximum source compatibility, maximum binary compatibility, and interoperability for 32-bit applications. In fact, most of the system commands that run and have been built on the Solaris 64-bit implementation are 32-bit programs. Note – This Solaris release supports systems that use the SPARC® and x86 families of processor architectures: UltraSPARC®, SPARC64, IA-32, AMD64. The supported SPARC based systems are based on the Solaris Sun Hardware Platform Guide. The supported X86 based systems appear in the Solaris Hardware Compaatibility List. This document cites any differences between the platform types. In this document the term “X86” refers to the Intel 32–bit family of microprocessors and compatible 64–bit and 32–bit microprocessors made by AMD. For supported systems, see the Solaris Hardware Compaatibility List The major differences between the 32-bit and the 64-bit application development environments are that 32-bit applications are based on the ILP32 data model, where ints, longs, and pointers are 32 bits, while 64-bit applications are based on the LP64 model, where longs and pointers are 64 bits and the other fundamental types are the same as in ILP32. Most applications can remain as 32-bit programs with no changes required. Conversion is necessary only if the application has one or more of the following requirements: I Needs more than 4 gigabytes of virtual address space I Reads and interprets kernel memory through use of the libkvm library, and /dev/mem,or/dev/kmem files 7 I Uses /proc to debug 64-bit processes I Uses a library that has only a 64-bit version I Needs full 64-bit registers to do efficient 64-bit arithmetic Specific interoperability issues can also require code changes. For example, if your application uses files that are larger than 2 gigabytes, you might want to convert the application to 64-bit. In some cases, you might want to convert applications to 64-bit for performance reasons.