Pallapa Sripairojkul Id

Slides:



Advertisements
งานนำเสนอที่คล้ายกัน
โครงสร้างโปรแกรมภาษา JAVA
Advertisements

INTRODUCTION TO C LANGUAGE
Introduction to C Introduction to C.
โครงสร้างโปรแกรมภาษา C
Texture การประมวลผลภาพแบบดิจิตอล Ian Thomas
กระบวนการ (Process).
Chapter 8 : Logic Modeling & Data Modeling
รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี
แนะนำการเขียนโปรแกรมภาษา C Introduction to C Programming Language
Control Statement if..else switch..case for while do-while.
สภาวะแวดล้อมในขณะโปรแกรมทำงาน
Software คือ ชุดคำสั่งหรือ ขั้นตอนการทำงานของคอมพิวเตอร์
Lecture No. 3 ทบทวนทฤษฎีและแบบฝึกหัด
Stack.
Structure Programming
โครงสร้างภาษาซี.
การใช้งานคอมพิวเตอร์ และ อินเตอร์เน็ตเบื้องต้น
โปรแกรมย่อย : Pascal Procedure
การประกาศตัวแปร “ตัวแปร” คือสิ่งที่เราสร้างขึ้นมาเพื่อใช้เก็บค่าต่างๆและอ้างอิงใช้งานภายในโปรแกรม ตามที่เรากำหนดขึ้น การสร้างตัวแปรขึ้นมาเราเรียกว่า.
Mind map (From Wikipedia, the free encyclopedia)
ขั้นตอนการแปลงไฟล์.
ขั้นตอนการแปลงไฟล์.
Functions & Sub Program ฟังก์ชันและโปรแกรมย่อย
การวิเคราะห์ประสิทธิภาพของอัลกอริธึม (Performance Analysis)
ให้ประหยัดการใช้หน่วยความจำ (space) ด้วยความรวดเร็ว (time)
Black Hat.
แนะนำการเขียนโปรแกรมภาษา C Introduction to C Programming Language
เซกเมนต์ (Segment) โครงสร้างคอมพิวเตอร์ และภาษาแอสเซมบลี้
Page: 1 โครงสร้างคอมพิวเตอร์ และภาษาแอสเซมบลี้ ผศ. บุรินทร์ รุจจน พันธุ์.. ปรับปรุง 19 ตุลาคม 2555 Introduction to Batch.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 22 มิถุนายน 2550 ความผิดพลาดที่พบ บ่อย มหาวิทยาลัยเนชั่น.
Process Analysis การวิเคราะห์กระบวนการ
Introduction to C Language
ตัวแปรกับชนิดของข้อมูล
Memory Management ในยุคก่อน
หน่วยประมวลผลกลางและหน่วยความจำ Central Processing Unit and Memory
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Java Programming Language.
List ADTs By Pantharee S..
ประวัติและขั้นตอนการพัฒนาโปรแกรมภาษาซี
การสร้าง WebPage ด้วย Java Script Wachirawut Thamviset.
Week 2 Variables.
Basic Stamp Microcontroller
Computer Programming for Engineers
ระบบคอมพิวเตอร์และการประมวลผล
บทที่ 3 การจ่ายงาน (Process Management).
หลักสูตรอบรมครู คอมพิวเตอร์ หลักสูตรอบรมครู คอมพิวเตอร์ หลักสูตรที่ ๑ ทักษะการโปรแกรม เบื้องต้น วันที่สาม.
เฉลิมชัย ประเทืองรัตน์ อาจารย์ประจำหมวด คอมพิวเตอร์ วุฒิทางการศึกษา วิทยาศาสตรบัณฑิต สาขาเทคโนโลยีสารสนเทศและการสื่อสาร.
โครงสร้าง ภาษาซี.
แนะนำการเขียนโปรแกรมภาษา C Introduction to C Programming Language
Programming & Algorithm
ว เคมีพื้นฐาน พันธะเคมี
1 สตริง (String) การประกาศค่าตัวแปรสตริง การกำหนดค่าสตริง การอ้างอิงตัวอักษรแต่ละตัวในสตริง ฟังก์ชั่นที่ใช้ในการจัดการสตริง ฟังก์ชั่นในการเปลี่ยนรูปแบบของสตริง.
นายรัฐราษฎร์ เกื้อสกุล 1. 2 Disk Password Protection เป็นชุดของโปรแกรมสำหรับปกป้องและจำกัด การเข้าถึง Harddisk สามารถปกป้อง Disk/Partition ด้วย Password,
Syntax and Semantics ธนวัฒน์ แซ่เอียบ.
Computer Programming การเขียนโปรแกรม คอมพิวเตอร์ สัปดาห์ที่ 6 คำสั่งควบคุมการทำงานแบบ เงื่อนไขและคำสั่งควบคุมการ ทำงานแบบวนซ้ำ.
วิชาเทคโนโลยีคอมพิวเตอร์และระบบปฏิบัติการ รหัสวิชา Computer Technology and Operating System บทที่ 1 เทคโนโลยีคอมพิวเตอร์ อ.รจนา วานนท์ Master.
Computer Program คือ ขั้นตอนการทำงาน ของคอมพิวเตอร์
ครูรุจิรา ทับศรีนวล “Room service”. “Room service”
Static Libraries ธวัชชัย เอี่ยมไพโรจน์. Static Libraries It is the simplest form of library. It is a collection of object files kept together in a ready-to-use.
PHP FRAMEWORK – Web Programming and Web Database Asst. Prof. Dr. Choopan Rattanapoka.
1 exit() and break C++ provides a way to leave a program early (before its natural finish) with the exit() function. The format of exit() is as follows:
Multimedia Systems รศ. ดร. บุญวัฒน์ อัตชู
พื้นฐานการเขียนแบบทางวิศวกรรม
หน่วยที่ 2 ข้อมูลและสารสนเทศ
บทที่ 1 ความรู้เบื้องต้น เกี่ยวกับระบบสารสนเทศ
การจัดการไฟล์ File Management.
บทที่ 3 การจัดการหน่วยความจำ (Memory Management)
โครงการสัมมนาเชิงปฏิบัติการบูรณาการภาครัฐและเอกชนในการจัดยุทธศาสตร์เศรษฐกิจภาคตะวันออก This template can be used as a starter file to give updates for.
สถิติเพื่อการวิเคราะห์ข้อมูล
สารสนเทศศาสตร์เบื้องต้น
Memory Management Ex. C = A + B A typical instruction-execution cycle
ใบสำเนางานนำเสนอ:

Pallapa Sripairojkul Id. 4322043 Shared Library Pallapa Sripairojkul Id. 4322043

Topics Overview Binding time Shared library in practice Address space management Structure of shared library Creating shared library Linking with shared library Running with shared library The malloc hack and other shared library problems

รูปแสดงการประมวลผลโปรแกรม Source program Overview Compiler or assembler Compile time Object module Other object modules Linkage editor Load module System library load time Dynamically Loaded system library loader รูปแสดงการประมวลผลโปรแกรม Execution time (run time) In-memory binary memory image

Overview Shared library consists of executable code that can be located at any available address in memory Only one copy of shared library’s instructions is loaded The system shares that one copy among multiple programs instead of loading a copy for each program using the library , as in the case with archive (static) library

Overview Advantages Program linked with shared libraries don’t need to be recompiled and relinked when changes are made to those libraries. The use of shared libraries occupies less space in memory and on disk. When multiple programs are linked to a single shared library, the amount of physical memory used by each process can be significantly reduced.

Shared library vs Archive library Shared library Archive library - ld - ar - can be positioned at any - fixed location in process’s available position. Loader private virtual address space assigns a location in private virtual address space - is in /usr/shlib - is in /usr/lib - naming prefix “lib” and - prefix “lib” end with suffix end with suffix “.so” “.a”

Example Main() { ... printf( “How do you like this manual?\n” ); result = strcmp ( “I do.”, answer ); }

a.out file ที่สร้างขึ้นโดยใช้ archive library และ shared library FILE HEADER Program .text library .text for printf(3S) and strcmp(3C) Program .data library .data SYMBOL TABLE STRING TABLE FILE HEADER Program .text Program .data .lib SYMBOL TABLE STRING TABLE สร้างโดยlink editor อ้างถึง library code สำหรับ printf(3S) และ strcmp(3C) ถูกคัดลอกไปยังไฟล์โดย link editor

Processes using an Archive and a Shared Library อาจจะมีการนำไปใช้ในโปรเซสอื่นพร้อม ๆ กัน Archive Version Shared Version Address Space Library นำเข้าสู่ตำแหน่งของหน่วยความจำของโปรเซส Library code ที่อ้างถึงโดย .lib

Binding time Shared library ไม่ถูกนำไปไว้กับ linked program ปัญหาที่อาจเกิดขึ้น ไม่พบ shared library ที่ต้องการ จึงมีข้อความแสดงข้อผิดพลาดและจบการทำงาน มี shared library นั้นอยู่ แต่ library มีการเปลี่ยนแปลงเมื่อโปรแกรมผ่านการ link ไปแล้ว การเปลี่ยนแปลงที่จะไม่มีผลกระทบต่อโปรแกรมคือ การเปลี่ยนแปลงที่ไม่ไปเปลี่ยนตำแหน่งของ library ที่โปรแกรมเรียกใช้

Shared library in practice All three work nearly the same but the differences are instruction. SVR3.2  COFF format LINUX  a.out format BSD/OS  a.out and ELF format SVR3.2 ต้องการการเปลี่ยนแปลงใน linker เพื่อให้สนับสนุนการค้นหา shared library ขยายความสามารถของ OS ให้สนับสนุนการทำงานในเรื่องของ runtime startup LINUX ต้องการการปรับ linker เล็กน้อย และเพิ่ม system call เพื่อช่วยเหลือในการทำ library mapping BSD/OS ไม่มีการเปลี่ยนแปลงใด ๆ กับ linker หรือ OS แต่จะใช้ shell script เพื่อให้ argument ที่จำเป็นแก่ linker และ standard C library startup routine เพื่อ map กับ library

Address space management แต่ละ shared library จับจองส่วนของ address space ของโปรแกรมที่มีการเรียกใช้มันในขนาดที่คงที่ Library ที่ต่างกันต้องใช้ non-overlapping addresses ถ้ามันมีการใช้ในโปรแกรมเดียวกัน ใช้การปล่อยให้มีที่ว่างระหว่าง library แต่ละตัว เมื่อมันมีการ เปลี่ยนแปลงจนได้เวอร์ชันใหม่มา

Structure of shared library Shared library คือ an executable format file ที่มี library code และ data บรรจุอยู่ข้างใน File header, a.out,COFF, or ELF header (Initialization routine , not always present) Jump Table Code Global data Private data Shared library เริ่มด้วย bootstrap routine เล็ก ๆ ในการ map ส่วนที่เหลือของ library ตามด้วย jump table ซึ่งเก็บ exported address ของแต่ละ public routine ใน library Text section Exported data และ Private data

การสร้าง a.out ผู้ใช้สั่งให้ link editor ค้นหา shared library ด้วยวิธีเดียวกับ การสั่งให้ค้นหา archive library คือ $cc file.c –o file … -l library_file … และการลิงค์ทุก ๆ ไฟล์ในไดเรกทอรีปัจจุบันเข้าด้วยกัน กับ shared C library ผู้ใช้จะต้องใช้คำสั่งต่อไปนี้ $cc *.c –lc_s

Creating shared library ขั้นตอนพื้นฐาน กำหนดว่าที่ address ใดที่ library code และ data จะถูก load ลงไป ดู input library ให้ทั่วตลอดไลบรารี เพื่อดู exported code symbols ทั้งหมด สร้าง jump table ที่มีสมาชิกคือ exported code symbol. ถ้ามีการกำหนดค่าเริ่มต้น หรือ loader routineที่ตอนเริ่มต้นของ libraryให้ทำการคอมไพล์ หรือ แอสเซมเบิล สร้าง shared library : รัน linker และ link ทุก ๆ สิ่งเข้าด้วยกันเป็น executable format file ขนาดใหญ่ สร้าง stub library : ดึงเอา symbols ที่จำเป็นจาก stub routine ที่สร้างขึ้นมาใหม่สำหรับแต่ละlibrary routine ออก แล้วทำการคอมไพล์ stubs routine และรวมเข้าเป็น stub library.

Creating shared library More details in : Creating the jump table Creating the shared library Creating the stub library Version naming

Creating jump table

Creating the shared library

Creating the stub library

Version naming

Linking with shared library

Running with shared library

Shared library problems

Example /* file shrobj.c */ const char *myfunc() { return “hello world”; }

Example (cont.) /* file hello.c */ #include <stdio.h> extern const char *myfunc() main() { printf(“%s\n”,myfunc()); return 0; }

Example (cont.) $ setenv LD_LIBRARY_PATH /stud/43/g4322043/… $ cc –fpic –c $ cc –shared –o libshared.so shrobj.o $ cc hello.c libshared.so $ ./a.out

Summary Using any shared library almost always saves disk storage space, memory, and computer power Running Unix system on smaller machines makes the efficient use of these resources increasingly important. Therefore, you should normally use a shared library whenever it’s available

References -UNIX System V Programmer’s guide. AT&T Prentice-Hall. Eaglewood Cliffs. NJ. -Silberschatz, Abraham. Applied operating system concepts. John Wiley&Sons,Inc. 2000. -Linker and Libraries Guide Solaris 2.5. Sun Microsystem, Inc. -http://www.tru64unix.compaq.com/faqs/publications/base_doc/ DOCUMENTATION/HTML/AA-PS30D-TET1_thml/peg5.html #shlib_chap. -http://www.iecc.com/linker/linker09.html. -http://www.users.cs.umn.edu/~bailey/sharedobjects/ sharedobjects.html. -http://www.erlenstar.demon.co.uk/unix/faq_7.html -http://www.xidak.com/mainsail/v19docs/newhtml/ osu-UNIXU-D.html